码迷,mamicode.com
首页 > 编程语言 > 详细

Python之第十九天的努力--复习1

时间:2020-06-24 21:45:17      阅读:58      评论:0      收藏:0      [点我收藏+]

标签:pre   move   字符   去重   sde   代码   rem   def   外壳   

复习

  1. # str
    # upper   lower
    # startswith    endswith
    # s = ‘Python世界‘
    # print(s.upper())
    # print(s.lower())
    # print(s.startswith(‘P‘))
    # print(s.endswith(‘界‘))
    
    
    # replace
    # msg = ‘zs 很厉害,zs王者打的很好‘
    # msg1 = msg.replace(‘zs‘,‘ls‘)
    # msg2 = msg.replace(‘zs‘,‘ls‘,1)
    # print(msg1)
    # print(msg2)
    
    
    # strip
    # s = ‘ \t弟弟\n‘
    # print(s.strip())
    
    # s = ‘qqw弟弟asd‘
    # print(s.strip(‘asdqw‘))
    
    
    # split
    # s = ‘zs ls ww‘
    # s1 = s.split()
    # print(s1)
    
    # s = ‘zs:ls:ww‘
    # s2 = s.split(‘:‘)
    # print(s2)
    
    # s2 = ‘:zs:ls:ww‘
    # s3 = s2.split(‘:‘)
    # s4 = s2.split(‘:‘,2)
    # print(s3)
    # print(s4)
    
    
    # join
    # s = ‘zs‘
    # s1 = ‘+‘.join(s)
    # print(s1)
    
    # s = [‘zs‘,‘ls‘,‘ww‘]
    # s1 = ‘:‘.join(s)
    # print(s1)
    
    
    # format
    # 格式化输出
    
    
    # is系列
    # name = ‘hcy123‘
    # print(name.isalnum())
    # print(name.isalpha())
    # print(name.isdecimal())
    
    
    
    
    # list
    # 增
    # l1 = [‘zs‘, ‘ls‘, ‘ww‘, ‘zl‘, ‘kk‘ ]
    # append    追加
    # l1.append(‘dd‘)
    # print(l1)
    
    # insert
    # l1.insert(1,‘dd‘)
    # print(l1)
    
    # extend
    # l1.extend(‘abcd‘)
    # print(l1)
    
    
    # 删
    # l1 = [‘zs‘, ‘ls‘, ‘ww‘, ‘zl‘, ‘kk‘ ]
    # pop
    # l1.pop(2)
    # print(l1)
    
    # remove    删头一个
    # l1.remove(‘ww‘)
    # print(l1)
    
    # clear
    # l1.clear()
    # print(l1)
    
    # del
    # del l1[-1]
    # print(l1)
    # del l1[::2]
    # print(l1)
    
    
    # 改
    # 索引切片
    
    
    # 查
    # 索引切片
    
    
    
    
    # tuple
    # 元组的拆包
    # a,b = (1,2)
    # print(a,b)
    
    
    
    # range
    
    
    
    
    # dict
    # 增
    # dic = {‘name‘:‘zs‘,‘age‘:18}
    # dic[‘sex‘] = ‘男‘
    # print(dic)
    # 有则改之  无则加之
    
    # setdefault
    # dic = {‘name‘:‘zs‘,‘age‘:18}
    # dic.setdefault(‘sex‘,‘男‘)
    # print(dic)
    # 有则不变  无则加之
    
    
    # 删
    # pop
    # dic = {‘name‘:‘zs‘,‘age‘:18}
    # dic.pop(‘age‘)
    # print(dic)
    
    
    # 改
    # 正常改
    
    
    # 查
    # get
    # dic = {‘name‘:‘zs‘,‘age‘:18}
    # l1 = dic.get(‘age‘)
    # l2 = dic.get(‘sex‘,‘无‘)
    # print(l1)
    # print(l2)
    
    
    # keys()
    # dic = {‘name‘:‘zs‘,‘age‘:18}
    # print(list(dic.keys()))
    
    # values()
    # dic = {‘name‘:‘zs‘,‘age‘:18}
    # print(list(dic.values()))
    
    # items()
    # dic = {‘name‘:‘zs‘,‘age‘:18}
    # print(dic.items())
    # for a,b in dic.items():
    #     print(a,b)
    
  2. id == is

    id:返回地址

    ==:比较是否相等

    is:比较地址是否一样

  3. 代码块

    • 一个文件就是一个代码块
    • 交互式界面一行就是一个代码块
  4. 两个机制

    • 统一代码块下的缓存机制
      • 所有的数字,bool,几乎所有的字符串
      • 提升性能,节省内存
    • 不同代码块下的缓存机制:小数据池
      • -5~256数字,bool,一定规则的字符串
      • 提升性能,节省内存
  5. 集合

    # 集合  无序
    # set
    # 空集合   set()
    
    # 增
    # set1 = {‘zs‘, ‘ls‘, ‘ww‘, ‘zl‘, ‘kk‘, ‘tt‘}
    # add
    # set1.add(‘dd‘)
    # print(set1)
    
    # updata 迭代着增
    # set1.update(‘abcd‘)
    # print(set1)
    
    
    # 删
    # set1 = {‘zs‘, ‘ls‘, ‘ww‘, ‘zl‘, ‘kk‘, ‘tt‘}
    # remove
    # set1.remove(‘ww‘)
    # print(set1)
    
    # pop   随机删除
    # set1.pop()
    # print(set1)
    
    
    # 用于列表去重
    # li = [1, 1, 2, ‘hhh‘, 2, 2, ‘hhh‘, 3, 4, 5, 6, ‘hhh‘, 6, 6]
    # set1 = set(li)
    # l1 = list(set1)
    # print(l1)
    
  6. 深浅copy

    • 浅copy:copy一个外壳,里面值的地址不变。
    • 深copy:只有不可变类型数据不变。

Python之第十九天的努力--复习1

标签:pre   move   字符   去重   sde   代码   rem   def   外壳   

原文地址:https://www.cnblogs.com/szheng/p/13189753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!