ABOUT
Danny Man
I’m Danny, and let me give you a warm welcome to visit my blog site. I hope you’ll enjoy it. Also, you can visit my HOME PAGE to learn more about me.
SEARCH
注意Python的共享引用
Python中的共享引用是随处可见的,这也就意味着随时注意该行为是非常重要的,否则就可能出错。假设我们需要创建一个大小为5x5的矩阵并以数字0对矩阵进行初始化,根据Python的一些特点和使用技巧,很可能会这样来做:>>> matrix = [[0] * 5] * 5
>>> for row in matrix:
print row
[0, 0, 0, 0, 0]
[0, ...