zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    谷歌BERT预训练源码解析(二):模型构建
    python 直接if判断和is not None的区别
    pytorch nn.Embedding
    独家 | TensorFlow 2.0将把Eager Execution变为默认执行模式,你该转向动态计算图了
    Facebook 发布深度学习工具包 PyTorch Hub,让论文复现变得更容易
    Hive与数据库的异同
    Linux自动删除n天前备份
    Haproxy安装与配置
    Nagios监控磁盘
    Nagios监控Oralce
  • 原文地址:https://www.cnblogs.com/www924121851/p/8612957.html
Copyright © 2011-2022 走看看