Python中关于列别生成式的奇怪现象
a = 4 b = 4 class A: a = 2 b = 2 arr = [[0 for i in range(a)] for j in range(b)] A = A() print(A.arr)
得到的结果为[[0, 0, 0, 0], [0, 0, 0, 0]]
为啥a取到全局的值,而b取到局部的值?
a = 4 b = 4 class A: a = 2 b = 2 arr = [[0 for i in range(a)] for j in range(b)] A = A() print(A.arr)
得到的结果为[[0, 0, 0, 0], [0, 0, 0, 0]]
为啥a取到全局的值,而b取到局部的值?
相关推荐