py字符串练习

1.http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html 取得校园新闻的编号

'http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'.rsplit('.html')[0][-9:]

2.https://docs.python.org/3/library/turtle.html 产生python文档的网址

str1 = 'http://docs.python.org/3/library/'
str2 = '.html'
str= str1 + 'turtle' + str2 

3.http://news.gzcc.cn/html/xiaoyuanxinwen/4.html 产生校园新闻的一系列新闻页网址

for i in range(48):
        print('http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i))

4.练习字符串内建函数:strip,lstrip,rstrip,split,count.用函数得到校园新闻编号;用函数统计一歌词中单词出现的次数;将字符串分解成一个个的单词。

'http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'.rsplit('.html')[0][-9:]
str ='''I'm a big big girl
  In a big big world
  It's not a big big thing if you leave me
  But I do do feel
  that I too too will miss you much
  Miss you much.
I can see the first leaf falling
  It's all yellow and nice
  It's so very cold outside
  Like the way I'm feeling inside
  I'm a big big girl
  In a big big world
  It's not a big big thing if you leave me
  But I do do feel
  that I too too will miss you much
  Miss you much.
Outside it's now raining
  And tears are falling from my eyes
  Why did it have to happen
  Why did it all have to end
  I'm a big big girl
  In a big big world
  It's not a big big thing if you leave me
  But I do do feel
  that I too too will miss you much
  Miss you much.
I have your arms around me ooooh like fire
  But when I open my eyes
  You're gone.
I'm a big big girl
  In a big big world
  It's not a big big thing if you leave me
  But I do do feel
  that I too too will miss you much
  Miss you much.
I'm a big big girl
  In a big big world
  It's not a big big thing if you leave me
  But I do feel that will miss you much
  Miss you much.'''
str.count('girl')
str = 'In a big big world'
str.split()

 5.分别定义字符串,列表,元组,字典,集合,并进行遍历。总结列表,元组,字典,集合的联系与区别。

str = 'hello'  # 字符串
for i in str:
    print(i)

lis = ['ps', 'ae', 'pr']  # 列表
for i in lis:
    print(i)

tp = ('ps', 'ae', 'pr')  # 元组
for i in tp:
    print(i)

d = {'ps': 1, 'ae': 2, 'pr': 3}  # 字典
for i in d:
    print(i + ':' + str(d.get(i)))
s = set(['ps', 'ae', 'pr'])  # 集合
for i in s:
print(i)

  列表有序,可排序,可修改,可增删

  元组有序,可排序,不可修改,可增删

  字典根据哈希值计算获得其位置,可排序,可修改,可增删,k-v,k不可重复

  集合和字典一样,但只有k

转载于:https://www.cnblogs.com/www924121851/p/8612957.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值