随笔分类 - 数据类型
元组,集合,字典,列表
摘要:数据类型(8) int 123,456 float 2.3 str strs = ' s sssss ' #大小写 # 转小写 print(strs.lower()) # 转大写 print(strs.upper()) #首字母大写 print(strs.title()) # 大小写互转 字符串替换
阅读全文
摘要:集合特性,元素唯一,不可重复,可以去重 s = print(s) 通过集合进行去重 lists = [1,2,2,2,5,1,1,2,3,3,5,6,5,6,4] s = set(lists) print(s) 遍历查询 for i in s: print(i) 删除集合 方法一del函数 prin
阅读全文
摘要:{}使用大括号定义 dicts = print(dicts['hello']) dict函数定义 dic = dict([['hello','world']]) print(dic) dict函数下fromkey函数定义,批量生成字典的键值,同时去除相同的键 dic = dict.fromkeys(
阅读全文
摘要:列表的添加 list = [] 方法一 list.append('hello')#append函数在列表后面添加 list.append('world') print(list) 方法二 list.extend(['hello','world'])#extend函数在列表后面添加 print(lis
阅读全文
摘要:元组不能增删改 tuple元组函数 t = (1,2,3,4)#()括号定义 tt = tuple([1,2,3,4])#tuple函数定义 print(t,tt) 遍历元组 for i in t: print(i) 遍历元组下标 for i in range(len(t)): print(i) 元
阅读全文