博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
字符串练习
阅读量:5229 次
发布时间:2019-06-14

本文共 1841 字,大约阅读时间需要 6 分钟。

字符串练习:

http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html

取得校园新闻的编号

acc="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"print(acc[-14:-5])

docs.python.org/3/library/turtle.html

产生python文档的网址

abb1="http://doc.python.org/3/library/"abb2=".html"abb3="turtle"print(abb1+abb3+abb2)

http://news.gzcc.cn/html/xiaoyuanxinwen/4.html

产生校园新闻的一系列新闻页网址

add1="http://news.gzcc.cn/html/xiaoyuanxinwen"add2=".html"for i in range(2,10):    add=add1 + str(i) + add2    print(add)

练习字符串内建函数:strip,lstrip,rstrip,split,count

用函数得到校园新闻编号

a="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"print(a.rstrip(".html").split("_")[1])

用函数统计一歌词中单词出现的次数

sing=""" 想带你逃学看一场演唱会 想你难过时在我怀中流泪 想和你背包走遍天南地北 想你共我尝尽人生的滋味 想下雨时小伞中有你依偎 想把酒言欢时也有你作陪 想我们做的风筝它也会飞 有你在身边就很美 简简单单 不说未来 平平淡淡 心口难开 我想我也许不够坏 离开眼泪就掉下来 忙忙乱乱 头脑空白 磕磕绊绊 总受伤害 这一次我要够勇敢 和过去说拜拜"""print(sing.count("想"))

将字符串分解成一个个的单词。

article="""China is a big old country and it has a history of more than five thousand years.We are proud of its culture and part of the culture even influences the world greatly. For example, the thought of Confucius. As Chinese economy develops very fast and plays an important role in the world,more and more foreigners learn mandarin in Confucius institutions. The essence of Chinese traditional culture can be tested by the time. It units the whole nation and no matter what kinds of disaster comes, we will fight together for the country’s future. Today, many young people lose faith in traditional culture and they are crazy for the western culture. They follow the western fashion and think we are the old style.But some day, they will realize they are wrong to abandon traditional culture."""a1=article.replace(","," ").replace("."," ").replace("  "," ").replace("’"," ").replace("\n","").split(" ")print(a1)

转载于:https://www.cnblogs.com/SOLARLKS/p/8616688.html

你可能感兴趣的文章
Java实现二分查找
查看>>
优秀员工一定要升职吗
查看>>
[LintCode] 462 Total Occurrence of Target
查看>>
springboot---redis缓存的使用
查看>>
架构图-模型
查看>>
Java -- Swing 组件使用
查看>>
Software--Architecture--DesignPattern IoC, Factory Method, Source Locator
查看>>
黑马程序员_Java基础枚举类型
查看>>
[ python ] 练习作业 - 2
查看>>
一位90后程序员的自述:如何从年薪3w到30w!
查看>>
在.net core上使用Entity FramWork(Db first)
查看>>
System.Net.WebException: 无法显示错误消息,原因是无法找到包含此错误消息的可选资源程序集...
查看>>
UIImage 和 iOS 图片压缩UIImage / UIImageVIew
查看>>
MongoDB的数据库、集合的基本操作
查看>>
ajax向后台传递数组
查看>>
疯狂JAVA16课之对象与内存控制
查看>>
[转载]树、森林和二叉树的转换
查看>>
软件测试-----Graph Coverage作业
查看>>
django ORM创建数据库方法
查看>>
创建Oracle synonym 详解
查看>>