摘要: global 定义一个或多个全局变量 globals() 存储所有全局变量 locals() 存储当前局部区域内,所有局部变量及方法 nonlocal 定义一个在闭包函数内,内部函数引用外部函数的属性 def outer(): n = 1 def inner(): nonlocal n n=2 pr 阅读全文
posted @ 2019-12-06 09:50 去遇见最好的自己 阅读(166) 评论(0) 推荐(0) 编辑
摘要: # 解压赋值 a,b = (1,2) print(a,b) # 1 2 # 交叉赋值 a = 1 b = 2 a,b = b,a print(a,b) # 2 1 # 按指定条件给字典排序 test = {'a':1,'b':3,'c':2} res = dict(sorted(test.items 阅读全文
posted @ 2019-12-06 09:30 去遇见最好的自己 阅读(153) 评论(0) 推荐(0) 编辑