字符串练习

字符串练习:

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])

https://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)

posted on 2018-03-21 15:08  嘻嘻嘻宸  阅读(101)  评论(0编辑  收藏  举报