zoukankan      html  css  js  c++  java
  • 字符串练习

    1.字符串练习:

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

    取得校园新闻的编号

    com= "http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
    print(com.rstrip(".html").split("_")[1])

    https://docs.python.org/3/library/turtle.html

    产生python文档的网址

    tt='https://docs.python.org/3/library/turtle.html'
    print(tt)

    http://news.gzcc.cn/html/xiaoyuanxinwen/4.html

    产生校园新闻的一系列新闻页网址

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

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

    用函数得到校园新闻编号

    com2 = 'http://news.gzcc.cn/html/xiaoyuanxinwen/'
    com3 = '.html'
    for i in range(2,20):
    print( com2 + str(i) + com3)

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

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

    song = '''
    我一生的黄金时代
    细看过沉默的大多数
    验证本质无能的愤怒
    行驶特立独行的路途
    我一生的黄金时代
    细看过沉默的大多数
    验证本质无能的愤怒
    行驶特立独行的路途
    只等有一天
    你说出水中有蜃楼
    我就与你拂袖而奔
    整个灵魂交付与你
    想变成天上忽明忽暗的云朵
    想吃掉世上最美味的一切
    一想到你呀 我这张脸就泛起微笑
    爱你就像爱生命
    爱你就像爱生命
    当我跨过沉沦的一切
    向着永恒开战的时候
    你是我不倒的旗帜
    爱你就像爱生命
    爱你就像爱生命
    流年似水经过
    阿芙罗蒂从浪花里浮现
    淡淡地爱着海流山川
    全心全意爱另一座冰山
    想变成天上忽明忽暗的云朵
    想吃掉世上最美味的一切
    一想到你呀 我这张脸就泛起微笑
    爱你就像爱生命
    爱你就像爱生命
    当我跨过沉沦的一切
    向着永恒开战的时候
    你是我不倒的旗帜
    爱你就像爱生命
    什么都不是爱的对手
    与之相配的 只有爱
    别怕一切美好消失
    来吧 先让它存在
    爱你就像爱生命
    爱你就像爱生命
    爱你就像爱生命
    print('爱你就像爱生命在歌里一共出现了'+ str(song.count('爱你就像爱生命')) + '次')

    2.组合数据类型练习

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

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

    string = 'Live or Die that is the question '
    print(string.split())

    s = "(1,2,3)"
    for a in range(len(s)):
    print(s[a])


    list = ['people','human','money']
    for b in list:
    print(b)

    for c in range(len(list)):
    print(list[c])


    tuple = ('people','human','money')
    for d in tuple:
    print(d)
    for e in range(len(tuple)):
    print(tuple[e])


    dict = {'people':10,'human':16,'money':28}
    for key in dict:
    print(dict[key])


    dom = set(['people','human','money'])
    for f in dom:
    print(f)

  • 相关阅读:
    A Deep Dive Into Draggable and DragTarget in Flutter
    使用joda-time工具类 计算时间相差多少 天,小时,分钟,秒
    XmlDocument.load 读文件报异常:文件正被其它线程使用,解决方法
    拼多多是怎么骗你的?
    东北话中的满语
    唐郑国公魏征金口“斩龙台”梦斩泾河黄龙的传说
    Asp.Net Form表单控件的回车默认事件
    UpdatePanel 控件,客户端事件生命周期踩坑
    Javascript 严格模式(strict mode)详解
    代数、几何、分析 各自的范畴
  • 原文地址:https://www.cnblogs.com/shadows24/p/8619056.html
Copyright © 2011-2022 走看看