标签:ever 元组 where 组合 put color for ges lin
1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
str=‘‘‘Never look back, we said How was I to know I‘d miss you so? Loneliness up ahead, emptiness behind Where do I go? And you didn‘t hear All my joy through my tears All my hopes through my fears Did you know Still I miss you somehow From the bottom of my broken heart There‘s just a thing or two I‘d like you to know You were my first love, you were my true love From the first kisses to the very last rose From the bottom of my broken heart Even though time may find me somebody new You were my real love, I never knew love ‘Til there was you From the bottom of my broken heart Baby,I said, please stay. Give our love a chance for one more day We could have worked things out Taking time is what love is all about But you put a dart Through my dreams through my heart And I‘m back where I started again‘‘‘ str=str.lower() str=str.replace(‘?‘,‘ ‘) str=str.replace("‘",‘ ‘) str=str.replace(‘,‘,‘ ‘) str=str.replace(‘.‘,‘ ‘) print(str) str=str.count(‘love‘) print("love出现的次数:",str)
2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
wl=list(‘2213133122‘)
print(list)
print(wl)
wl.insert(5,‘2‘)
print("增:",wl)
wl.pop(3)
print("删:",wl)
wl[1]=‘3‘
print("改:",wl)
i=wl.index(‘3‘)
print("第一个3的下标:",i)
s=wl.count(‘1‘)
print("1分有:",s,"个")
t=wl.count(‘2‘)
print("2分有:",t,"个")
r=wl.count(‘3‘)
print("3分有:",r,"个")
3.简要描述列表与元组的异同。
答:同:列表与元组都是非常类似的,是内置的有序集合,都是可以嵌套的。
异:列表是一种有序的序列,正向递增、反向递减序号,可以随时添加和删除其中的元素,是可变的;而元组一旦初始化就不能修改了,是不可变的。
标签:ever 元组 where 组合 put color for ges lin
原文地址:http://www.cnblogs.com/zsy-97/p/7574118.html