字符串练习
2018-03-20 22:22 Molemole 阅读(180) 评论(0) 编辑 收藏 举报字符串练习:
http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html
取得校园新闻的编号
str='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html' str.rstrip('.html').split('/')[-1]
https://docs.python.org/3/library/turtle.html
产生python文档的网址
str='https://docs.python.org/3/library/turtle.html' print(str)
http://news.gzcc.cn/html/xiaoyuanxinwen/4.html
产生校园新闻的一系列新闻页网址
for i in range(10): str='http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i) print(str)
练习字符串内建函数:strip,lstrip,rstrip,split,count
用函数得到校园新闻编号
用函数统计一歌词中单词出现的次数
将字符串分解成一个个的单词。
str=''' 起来!不愿做奴隶的人们! 把我们的血肉筑成我们新的长城! 中华民族到了最危险的时候, 每个人被迫着发出最后的吼声。 起来!起来!起来! 我们万众一心, 冒着敌人的炮火,前进! 冒着敌人的炮火,前进! 前进!前进、进! ''' print(str.count('前进'))