摘要: # open 参数介绍 # file :用来指定打开的文件(不是文件的名字,而是文件的路径) # mode :打开文件时的模式,默认是r表示 只读 # encoding:打开文件时的编码方式 # file.read() 读取文件 # file.close() c操作完成文件后,关闭文件 # tell 阅读全文
posted @ 2020-07-22 17:10 XuanchenLi 阅读(1202) 评论(0) 推荐(0) 编辑
摘要: # 创建函数 def info(): # age = 18 # name = 'lxc' # print(age,name) print('我是李轩臣') print('我21') info() # 调用函数 执行一次 # 我是李轩臣 # 我21 # 定义函数求和 def he(): a=5 b=3 阅读全文
posted @ 2020-07-22 17:07 XuanchenLi 阅读(149) 评论(0) 推荐(0) 编辑
摘要: # # 1: 构建一个列表(使用列表推导式,和list(iterable) # # 和列表相加的方式完成 l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 'j', 'q', 'k', 'a'] l1 = [i for i in range(1,10)+list('jqka')] pr 阅读全文
posted @ 2020-07-17 16:01 XuanchenLi 阅读(323) 评论(0) 推荐(0) 编辑
摘要: # 作业 #写代码:有如下字典 # 按照要求实现每一个功能 # dict = {"k1":"v1","k2":"v2","k3":"v3"} # 1、请循环遍历出所有的key dic = {"k1":"v1","k2":"v2","k3":"v3"} re = dic.keys() for i in 阅读全文
posted @ 2020-07-17 15:50 XuanchenLi 阅读(819) 评论(0) 推荐(0) 编辑
摘要: # count 推导思路 词频统计 #统计 元素出现的次数 l1 = [1,2,3,5,4,1,2,3,6,4,5,88,99] l2 = list() # [元素,次数,元素,次数,..........................] for i in l1: # i 在 l1 循环 if i 阅读全文
posted @ 2020-07-17 15:27 XuanchenLi 阅读(198) 评论(0) 推荐(0) 编辑
摘要: # 枚举 # enumerate枚举,对于一个可迭代的(iterable)/可遍历的对象(如列表、字符串), # enumerate将其组成一个索引序列,利用它可以同时获得索引和值。 l = [5,'ni',6,'ow',9,5,6,] for i in enumerate(l): print(i) 阅读全文
posted @ 2020-07-17 15:16 XuanchenLi 阅读(115) 评论(0) 推荐(0) 编辑
摘要: # dic = {} print(type(dic)) se = {} print(type(se)) se = set() print(type(se)) # # # 创建空集合 se = set() # se = set(iterable) # 直接创建 集合的元素是不可变的 int str t 阅读全文
posted @ 2020-07-17 15:15 XuanchenLi 阅读(324) 评论(0) 推荐(0) 编辑
摘要: # iterable 》》》》》 。迭代器__iter__ re = range(5).__iter__() print(re) # <range_iterator object at 0x034A0FE0> 生成迭代器 print(re.__next__()) print(re.__next__( 阅读全文
posted @ 2020-07-17 15:12 XuanchenLi 阅读(99) 评论(0) 推荐(0) 编辑
摘要: #() 元组 # 元组的索引切片 # t = (1,2,3,5,6,8,9,5,67,2,3,) # print(t) print(type(t)) # <class 'tuple'> print(t[0]) print(t[3]) print(t[:3]) print(t[::3]) # tupl 阅读全文
posted @ 2020-07-17 15:09 XuanchenLi 阅读(86) 评论(0) 推荐(0) 编辑
摘要: a,b = 1,2 print(a,b) # 结果: # 1 2 a,b = ('你好','世界') # 这个用专业名词就叫做元组的拆包 print(a,b) # 结果: # 你好 世界 a,b = ['你好','大飞哥'] print(a,b) # 结果: # 你好 大飞哥 a,b = {'汪峰' 阅读全文
posted @ 2020-07-15 16:09 XuanchenLi 阅读(2610) 评论(0) 推荐(0) 编辑