摘要: 可迭代对象 能被for循环遍历的元素 lists = [1,2,3,4] for i in lists: print(i) 生成器是一种特殊的变量 斐波那契数列生成器 def get_data(num): x = 0 y = 1 for i in range(num): x,y = y,x+y yi 阅读全文
posted @ 2024-06-06 14:41 淡然。。 阅读(7) 评论(0) 推荐(0)
摘要: 用def定义一个函数 不定长函数 def hello(*args):#返回是一个集合 print(args) # print(min(args)) # print(max(args)) hello(5,2,1,6,3) def hello(**kwargs):#返回是一个字典 print(kwarg 阅读全文
posted @ 2024-06-06 14:03 淡然。。 阅读(5) 评论(0) 推荐(0)
摘要: from copy import copy,deepcopy lists = [1,2,3,4,5,[6]] new_lists = copy(lists) # print(new_lists) # lists.append(7) # print(lists,new_lists)#直接修改列表外元素 阅读全文
posted @ 2024-06-06 13:58 淡然。。 阅读(5) 评论(0) 推荐(0)
摘要: 数据类型(8) int 123,456 float 2.3 str strs = ' s sssss ' #大小写 # 转小写 print(strs.lower()) # 转大写 print(strs.upper()) #首字母大写 print(strs.title()) # 大小写互转 字符串替换 阅读全文
posted @ 2024-06-05 14:53 淡然。。 阅读(23) 评论(0) 推荐(0)
摘要: 集合特性,元素唯一,不可重复,可以去重 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 阅读全文
posted @ 2024-06-05 14:45 淡然。。 阅读(16) 评论(0) 推荐(0)
摘要: {}使用大括号定义 dicts = print(dicts['hello']) dict函数定义 dic = dict([['hello','world']]) print(dic) dict函数下fromkey函数定义,批量生成字典的键值,同时去除相同的键 dic = dict.fromkeys( 阅读全文
posted @ 2024-06-05 14:43 淡然。。 阅读(23) 评论(0) 推荐(0)
摘要: 列表的添加 list = [] 方法一 list.append('hello')#append函数在列表后面添加 list.append('world') print(list) 方法二 list.extend(['hello','world'])#extend函数在列表后面添加 print(lis 阅读全文
posted @ 2024-06-05 14:43 淡然。。 阅读(18) 评论(0) 推荐(0)
摘要: 元组不能增删改 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) 元 阅读全文
posted @ 2024-06-05 14:42 淡然。。 阅读(7) 评论(0) 推荐(0)
点击右上角即可分享
微信分享提示