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

  • 相关阅读:
    (转)两千行PHP学习笔记
    PHP语言 -- 基础
    数据库-T-SQL 语句-高级查询
    数据库-T-SQL 语句-简单查询
    数据库-T-SQL 语句-创建表,删除表,CRUD操作的添加数据,修改数据,删除数据
    PHP 数组
    PHP函数
    PhP 基础
    无缝循环
    l两张图片轮播
  • 原文地址:https://www.cnblogs.com/www924121851/p/8612957.html
Copyright © 2011-2022 走看看