1.
s='''When I am down and oh my soul so weary
When troubles come
and my heart burdened be
Then I am still and wait here in the silence
Until you come and sit
a while with me.
You raise me up, so I can stand on mountains
You raise me up, to
walk on stormy seas
I am strong, when I am on your shoulders
You raise me up...
to more than I can be
You raise me upso
I can stand on mountains
You raise me up to walk on stormy seas
I am strong, when
I am on your shoulders
You raise me up...
to more than I can be
You raise me up, so
I can stand on mountains
You raise me up
to walk on stormy seas
I am strong, when
I am on your shoulders
You raise me up...
to more than I can be
You raise me up, so
I can stand on mountains
You raise me up, to walk on stormy seas
I am strong, when
I am on your shoulders
You raise me up...
to more than I can be
You raise me up...
to more than I can be '''
s=s.lower()
for i in ',.?':
s=s.replace(i,' ')
print(s.split(' '))
print(s.count('talk'))
print(s.count('anymore'))
2、列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
homework=list('134343633')
for i in range(len(homework)):
homework[i]=int(homework[i])
print(homework)
print(homework.index(6))
print(homework.count(1))
print(homework.count(3))
运行结果:
[1, 3, 4, 3, 4, 3, 6, 3, 3]
6
1
5
3、简要描述列表与元组的异同。
元组和列表十分类似,但是元组是不可变的.
也就是说你不能修改元组。
元组通过圆括号中用逗号分割的项目定义。
元组通常用在使语句或用户定义的函数能够安全地采用一组值的时候,
即被使用的元组的值不会改变。