摘要: 变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数。 1 2 3 4 5 6 def add(x,y,f): return f(x) + f(y) res = add(3,-6,abs) print(res) 1 2 3 4 5 6 def a 阅读全文
posted @ 2018-11-06 16:04 rongye 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 在函数内部,可以调用其他函数。如果一个函数在内部调用自身本身,这个函数就是递归函数。 1 2 3 4 5 6 7 8 9 10 11 12 13 def calc(n): print(n) if int(n/2) ==0: return n return calc(int(n/2)) calc(10 阅读全文
posted @ 2018-11-06 15:43 rongye 阅读(303) 评论(0) 推荐(0) 编辑
摘要: before change lian Oldboy edu.after change Lian YunNan Universitylian YunNan University 阅读全文
posted @ 2018-11-06 15:21 rongye 阅读(674) 评论(0) 推荐(0) 编辑
摘要: (1, 2, 3, 4, 5, 5)(1, 2, 4, 5, 5)1(2, 3, 4, 5, 6){'name': 'lian', 'age': 8, 'sex': 'f'}lian8{'name': 'lian', 'age': 8}lian8Lian{'age': 18, 'sex': 'm'} 阅读全文
posted @ 2018-11-06 15:03 rongye 阅读(118) 评论(0) 推荐(0) 编辑
摘要: in the test1in the test2in the test3None0(1, 'hello', ['alex', 'wupeiqi'], {'name': 'alex'}) 阅读全文
posted @ 2018-11-06 11:48 rongye 阅读(140) 评论(0) 推荐(0) 编辑
摘要: import timedef logger(): time_format = '%Y-%m-%d %X' time_current = time.strftime(time_format) with open('a.txt','a+') as f: f.write('%s end action\n' 阅读全文
posted @ 2018-11-06 11:33 rongye 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 详细文章: http://www.cnblogs.com/yuanchenqi/articles/5956943.html http://www.diveintopython3.net/strings.html 需知: 1.在python2默认编码是ASCII, python3里默认是unicode 阅读全文
posted @ 2018-11-06 10:18 rongye 阅读(298) 评论(0) 推荐(0) 编辑
摘要: 为了避免打开文件后忘记关闭,可以通过管理上下文,即: 1 2 3 with open('log','r') as f: ... 1 2 3 with open('log','r') as f: ... 1 2 3 with open('log','r') as f: ... 1 2 3 with o 阅读全文
posted @ 2018-11-06 09:53 rongye 阅读(128) 评论(0) 推荐(0) 编辑
摘要: #逐行读写f = open('yesterday','r',encoding='utf-8')f_new = open('yesterday3','w',encoding="utf-8")for line in f: if '等我享受' in line: line = line.replace('等 阅读全文
posted @ 2018-11-06 09:44 rongye 阅读(130) 评论(0) 推荐(0) 编辑