05 2018 档案

内置模块
摘要:(1)collections模块 (翻译:收藏)在内置数据类型(dict,list,set,tuple)的基础上,collections模块还提供了几个额外的数据类型:counter,deque,defaultdict,namedtuple和OrderedDict等。 1. namedtuple:生 阅读全文

posted @ 2018-05-13 16:14 python21-李伟 阅读(93) 评论(0) 推荐(0)

递归
摘要:在函数的内部调用自己递归的最大深度:998例子:猜年龄def age(n): #n = 1 ,n = 2 if n == 3: #n = 3 return 40 #返回40 else: return age(n+1)+2 #n = 2 ,n = 3print(age(1))# 递归求解二分查找算法: 阅读全文

posted @ 2018-05-11 23:59 python21-李伟 阅读(102) 评论(0) 推荐(0)

内置函数
摘要:ret = zip([1,2,3,4,5],('a','b','c','d'),(4,5)) #拉链方法print(ret)for i in ret: print(i)lst = [1, 4, 6, 7, 9, 12, 17]def func(num): if num % 2 == 0:return 阅读全文

posted @ 2018-05-04 23:01 python21-李伟 阅读(92) 评论(0) 推荐(0)

列表推导式
摘要:#麻烦办法new_lst = []for i in range(10): new_lst.append(i**2)print(new_lst)#简单办法print([i**2 for i in range(10)])# 小题下面列表中取余list_a = [1,2,3,-5,20,-7]print( 阅读全文

posted @ 2018-05-01 19:44 python21-李伟 阅读(135) 评论(0) 推荐(0)

生成器
摘要:判断是否可迭代和是否迭代器from collections import Iterable,Iteratorprint(range(10000))print(isinstance(range(10000),Iterable)) #是否可迭代print(isinstance(range(10000), 阅读全文

posted @ 2018-05-01 16:59 python21-李伟 阅读(94) 评论(0) 推荐(0)

导航