博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2019年2月24日

摘要: def test1(): print('in the test1') def test(): print('in the test') return test1 print(test) res = test() print(res()) in the test in the test1 None def foo(): name = 'majun' ... 阅读全文

posted @ 2019-02-24 22:48 MJ-majun 阅读(192) 评论(0) 推荐(0) 编辑

摘要: # 递归 def calc(n): print(n) if int(n/2) == 0: return n res = calc(int(n/2)) return res res = calc(10) print(res) 10 5 2 1 1 import time person_list = [ 阅读全文

posted @ 2019-02-24 21:57 MJ-majun 阅读(140) 评论(0) 推荐(0) 编辑

摘要: # 风湿理论之函数即变量 def foo(): print('from foo') bar() def bar(): print('from bar') foo() from foo from bar def bar(): print('from bar') def foo(): print('from foo') bar() foo() f... 阅读全文

posted @ 2019-02-24 16:37 MJ-majun 阅读(107) 评论(0) 推荐(0) 编辑

摘要: # 全局变量 如果函数的内容无 global关键字,优先读取全局变量,无法对全局变量重新赋值, name = 'mj' def change_name(): print('change_name',name) change_name() change_name mj # 但是对于可变类型,可以对内部 阅读全文

posted @ 2019-02-24 11:33 MJ-majun 阅读(109) 评论(0) 推荐(0) 编辑