本文原创,版权属作者个人所有,如需转载请联系作者本人。Q&微:155122733
--------------------------------------------------------------------------------------------------------
a+=1 代表在原值上更改
a=a+1相当于先定义一个变量,然后对新变量本身修改
#!/usr/bin/python
def test1(a): a+=a print(id(a))# display 140123195551624 print(a)# display [11, 22, 11, 22] def test2(a): a =a+a print(id(a))#display 140123195676424 print(a)# display [11, 22, 11, 22, 11, 22, 11, 22] nums = [11,22] test1(nums) print(nums)# display [11, 22, 11, 22] test2(nums) print(id(nums))#display 140123195551624 print(nums)# display [11, 22, 11, 22]