摘要: # f = open('json_file','w') # json.dump({'k':(1,2,3)},f) # f.close() # with open('json_file') as f: # ret = json.load(f) # print(ret,type(ret)) # ret 阅读全文
posted @ 2017-11-21 18:46 dwenwen 阅读(4388) 评论(0) 推荐(1) 编辑
摘要: import time # ret = time.time() #时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 # print(ret) #1510647685.4264479 # print(type(ret)) # 格式化的时间字符串strftime # ret 阅读全文
posted @ 2017-11-21 18:39 dwenwen 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 模块re re模块下的常用方法: 阅读全文
posted @ 2017-11-13 17:35 dwenwen 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 上面是我们对calc这个匿名函数的分析,下面给出了一个关于匿名函数格式的说明 阅读全文
posted @ 2017-11-11 12:06 dwenwen 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 哈希(是一种算法)hash,返回的是一串数字应用:数据的存储和查找, def func(x): return x and x.strip() l = ['test',None,'','str',' ','END'] ret = filter(func,l) print(list(ret)) def 阅读全文
posted @ 2017-11-11 11:47 dwenwen 阅读(191) 评论(0) 推荐(0) 编辑
摘要: def find_2(l,aim,start=0,end=None): if end == None:end = len(l) -1 if end >= start: mid = (end - start) // 2 + start if l[mid] > aim: ret = find_2(l,a 阅读全文
posted @ 2017-11-11 11:18 dwenwen 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 列表推导式 例一:30以内所有能被3整除的数 multiples = [i for i in range(30) if i % 3 is 0] print(multiples) # Output: [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] 例二:30以内所有能被3整除 阅读全文
posted @ 2017-11-11 11:06 dwenwen 阅读(462) 评论(0) 推荐(0) 编辑
摘要: 生成器表达式 y = [1,2,3,4,5,6,7,8] g = (i*i for i in y) #列表可以使用推导式,生成器也可以使用表达式 print(g) print(list(g)) #使用list把生成器强转成为列表 for i in g: print(i) laomuji=('鸡蛋%s 阅读全文
posted @ 2017-11-11 10:55 dwenwen 阅读(177) 评论(0) 推荐(0) 编辑
摘要: send 方法 def cloth(): for i in range(100): yield '衣服%s'%i g1 = cloth() g2 = cloth() print(g1.__next__()) print(g1.__next__()) for c in cloth(): print(c 阅读全文
posted @ 2017-11-11 10:51 dwenwen 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 动态函数 动态参数的应用 阅读全文
posted @ 2017-11-04 16:34 dwenwen 阅读(422) 评论(0) 推荐(0) 编辑