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

    str='We Chat'
    for i in str:
        print(i)
    
    list1=list('12345')
    for i in list1:
        print(i)

    字符串练习:

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

    取得校园新闻的编号

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

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

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

    用函数得到校园新闻编号

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

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

    str='''
    起来!不愿做奴隶的人们!
    把我们的血肉筑成我们新的长城!
    中华民族到了最危险的时候,
    每个人被迫着发出最后的吼声。
    起来!起来!起来!
    我们万众一心,
    冒着敌人的炮火,前进!
    冒着敌人的炮火,前进!
    前进!前进、进!
    '''
    print(str.count('前进'))

    2.组合数据类型练习

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

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

    str='We Chat'
    for i in str:
        i
    
    list1=list('12345')
    for i in list1:
        i
    
    tuple1=tuple('123456')
    for i in tuple1:
        i
    
    d={'W':'C','e':'h'}
    #d=dict(zip('We','Chat'))
    for i in d.keys():
        i
     for i in d.values():
        i
    
    s={'W','e','C','h','a','t'}
    for i in s:
        i

    列表和元组是有序的序列,字典和集合是无序的序列;

    列表和元组是牺牲时间节省内存;字典和集合是牺牲内存节省时间。

    列表:将字符串等基本数据类型储存起来,元素可重复,可嵌套其他数据类型

    元组:区别与列表是不可以修改定义好的元素

    字典:key-value组成的对形成一个元素,key不可重复

    集合:区别与列表是不可以有相同的元素

  • 相关阅读:
    66. 缓存字节流
    65. 练习(拷贝图片--边读边写)
    64. 输出字节流(FileOutputStream)
    63. (FileInputStream)输入字节流
    62. File类常用方法
    61. File类
    60. 枚举
    快速排序
    归并排序
    初级排序算法
  • 原文地址:https://www.cnblogs.com/1103a/p/8611809.html
Copyright © 2011-2022 走看看