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

  • 相关阅读:
    买二手房的税费详细版本
    实时推荐部分代码
    卡片推荐部分代码
    详解一下网络广告cpc、cpm、cpl、cpa、cps、cpr的计费方法是什么
    吴军硅谷来信《三板斧破四困境》
    JS实现的在线推荐逻辑
    mongo数据库时间存储的问题
    crontab 定时的陷阱
    【剑指offer】栈的压入、弹出序列
    【剑指offer】包含min函数的栈
  • 原文地址:https://www.cnblogs.com/www924121851/p/8612957.html
Copyright © 2011-2022 走看看