zoukankan      html  css  js  c++  java
  • 字符串、组合数据类型练习

    字符串练习:

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

    取得校园新闻的编号

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

      

    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(5):
        print('http://news.gzcc.cn/html/xiaoyuanxinwen/{ }.html'.format(i))
    

      

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

    用函数得到校园新闻编号

    str='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
    print(str.strip('.html').split('_')[1])
    

      

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

    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.'''
    print(str.count('big'))
    

      

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

    str='long time no see'
    print(str.split())
    

    2.组合数据类型练习

    分别定义字符串,列表,元组,字典,集合,并进行遍历。

    字符串

    string='Michael'
    for str in string:
        print(str)

    列表

    list=['Michael','Tracy','Bob','wangwu']
    for l in list:
        print(l)
    

    元祖

    tuple=('Michael','Tracy','Bob','wangwu')
    for tup in tuple:
        print(tup)
    

    字典

    dict = dict(zip('python', '123456'))
    for i in dict:
        print(i)
    for i in dict.keys():
        print(i)
    for i in dict.values():
        print(i)
    for i in dict.items():
        print(i)
    

    集合

    set={'Michael','Tracy','Bob','wangwu'}
    for i in set:
            print(i)
    

      

    总结列表,元组,字典,集合的联系与区别。

  • 相关阅读:
    SpringBoot+CXF下Https调用webservice跳过安全证书的配置
    程序员的长安十二时辰:Java实现从Google oauth2.0认证调用谷歌内部api
    springboot集成activiti6.0多数据源的配置
    activiti工作流委托功能的设计和实现
    vue.js带复选框表单的增删改查
    bootstrap-treeview后台Json数据的封装及前台的显示
    你好,Spring!
    超大份线程池,干杯,兄弟!陆
    嗯!这篇多线程不错!伍
    是兄弟!就来看这篇多线程!叁
  • 原文地址:https://www.cnblogs.com/dengjinxiu/p/8613183.html
Copyright © 2011-2022 走看看