标签:cost split with 统计 effect 增删改 rail ted 技术分享
1)实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
news = ‘‘‘ China hopes Singapore will support Chinese enterprises who wish to participate in the Singapore-Malaysia high-speed railway project, Premier Li Keqiang said on Tuesday. "China has cutting-edge, safe and reliable, cost-effective high-speed railway technology," Li said in his talks with visiting Singaporean Prime Minister Lee Hsien Loong. Malaysia and Singapore have agreed to build a 360-km high-speed rail link between Singapore and Kuala Lumpur, which is expected to start operation by December 2026 and cut travel time to about 90 minutes. Singapore welcomes Chinese businesses to the project, Lee said.‘‘‘ news=news.lower() print(news.count(‘china‘)) for i in ‘,.‘: news=news.replace(i,‘ ‘) print(news) words=news.split(‘ ‘) print(words)
结果如下所示:
2)列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
homework=list(‘123478526‘) for i in range(len(homework)): homework[i]=int(homework[i]) print(homework) print(homework.index(8)) print(homework.count(1)) print(homework.count(3))
结果如下所示:
3)简要描述列表与元组的异同。
元组一旦被赋值不能被更改,而列表被赋值后可以更改。
列表和元组所用的符号不同,列表的用方括号,元组的用圆括号。
标签:cost split with 统计 effect 增删改 rail ted 技术分享
原文地址:http://www.cnblogs.com/yuanyinglin/p/7565166.html