Python 引用传递问题

a = [['hello world','','']]
    b = a[0]
    print b
    b[0] = b[0] + '123'
    a.append(b)    
    print a
以上属于引用传递,打印输出为[['hello world123','',''],['hello world123','','']]

如果想不改变a的值,解决办法是将a[0]深拷贝一份后再操作
更详细说明见: https://www.cnblogs.com/loleina/p/5276918.html

猜你喜欢

转载自blog.csdn.net/u012474535/article/details/79270452