- 实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
lp='''You hid your skeletons, when I had shown you mine you woke the devil that I thought you left behind I saw the evidence the crimson soaking through ten thousand promises, ten thousand ways to lose... And you held It all but you were careless to let it fall you held it all and I was by your side Powerless I watched you fall apart and chased you to the end I'm left an empty mess, that words can not defend you'll never know what I became because of you ten thousand promises, ten thousand ways to lose... And you held It all but you were careless to let it fall''' print(lp.lower()) print(lp.replace(',',' ')) print(lp.count("you")) print(lp.split(" "))
- 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
hw=list("123321222") print(hw) hw.append("1") print("增加:",hw) hw.insert(2,"1") print("插入:",hw) hw.pop() print("删除:",hw) hw[5]=2 print('更改:',hw) print("第一个3分的下标:",hw.index("3")) print("1分的同学共有",hw.count("1"),"个") print("3分的同学共有",hw.count("3"),"个")
- 简要描述列表与元组的异同。
list与turple一样,都是处理一组有序项目的数据结构。列表应该包括在方括号中,我们可以在一个列表中添加,删除,或者是查询,即列表的值是可以改变的。元组的值则是不能改变,元组包括在圆括号里。
转载于:https://www.cnblogs.com/yin-yeah/p/7574114.html