1实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词.
aa='''Look at the stars,Look how they shine for you,And everything you do,Yeah, they were all Yellow.I came along,I wrote a song for you,And all the things you do,And it was called Yellow.So then I took my turn,Oh what a thing to have done,And it was all Yellow.Your skinOh yeah, your skin and bones,Turn into something beautiful,You know, you know I love you so,You know I love you so.I swam across,I jumped across for you,Oh what a thing to do.Cos you were all Yellow,I drew a line,I drew a line for you,Oh what a thing to do,And it was all Yellow.'''print(aa.lower())print(aa.replace(',',' '))print(aa.count("yellow"))print(aa.split(" "))
2列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
b=list('3121321321333121112113')b.append('1')b.insert(2,'2')b.pop()b.pop(7)print(b)print('3分的起始位置是',b.index('3'))print('1分的有',b.count('1'),'个')print('3分的有',b.count('3'),'个')
3简要描述列表与元组的异同。
答:
列表是一种有序的序列,正向递增、反向递减序列,可以随时添加和删除其中的元素,没有长度限制、元素类型可以不同;而元组与列表类似,可读取里面的元素,但是不能改变其中的元素。