1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。

s='''Success and failure is and walkers.
When you experience the enjoyment of victory, success and failure in the far away from you hide the corner, or wait in the waiting outside, you consider it.
Therefore, when one victory, enjoying the mood of the holiday, the more times, when the attack is over failure.
The former, the latter more lax degree will succeed. The former, the latter will not slack away a shot harvest it"success".
Who is to come, success and failure in the "twin", manipulation, and stand, vigorous... Step after of the road of life.
'''

#将所有将所有其他做分隔符(,.?!)替换为空格
for i in ',.?!':
    s=s.replace(i,' ')
print('其他分隔符替换为空格的结果:'+s+'\n')

#将所有大写转换为小写
s=s.lower()
print('全部转换为小写的结果:'+s+'\n')


#统计单词‘and’出现的次数
count=s.count('and')
print('单词and出现的次数为:',count)
print('\n')

#分隔出单词
s=s.split(' ')
print('分隔结果为:',s)

 

 

 

2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。

sss=list('121213123213223')
print(sss)    

#查询第一个3分的下标
print('第一个3分的下标',sss.index('3'))

#查询3分的同学有多少个
print('3分的同学有',sss.count('3'))

#查询1分的同学有多少个
print('1分的同学有',sss.count('1'))    

#加一个3分的同学
sss.append('3')
print('追加后的结果为:',sss)

#修改下标为5的同学的分数为3
sss[5]='5'
print('修改后的结果为:',sss)

#在下标为6的位置插入一个分数为3的同学
sss.insert(6,'3')
print('插入后的结果为:',sss)

#删除最后一个同学的分数
sss.pop()
print('删除后的结果为:',sss)

 

3.简要描述列表与元组的异同。

列表
list是处理一组有序项目的数据结构,即你可以在一个列表中存储一个序列的项目。列表中的项目。
列表中的项目应该包括在方括号中,这样python就知道你是在指明一个列表。一旦你创建了一个列表,你就可以添加,删除,或者是搜索列表中的项目。
由于你可以增加或删除项目,我们说列表是可变的数据类型,即这种类型是可以被改变的。
列表是可以嵌套的。

元组
元组和列表十分相似,不过元组是不可变的。即你不能修改元组。元组通过圆括号中用逗号分隔的项目定义。
元组通常用在使语句或用户定义的函数能够安全的采用一组值的时候,即被使用的元组的值不会改变。
元组可以嵌套。