python中+=和=+的区别
生活随笔
收集整理的這篇文章主要介紹了
python中+=和=+的区别
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
本文原創(chuàng),版權(quán)屬作者個(gè)人所有,如需轉(zhuǎn)載請聯(lián)系作者本人。Q&微:155122733
--------------------------------------------------------------------------------------------------------
a+=1 代表在原值上更改
a=a+1相當(dāng)于先定義一個(gè)變量,然后對新變量本身修改
#!/usr/bin/pythondef test1(a):a+=aprint(id(a))# display 140123195551624print(a)# display [11, 22, 11, 22] def test2(a):a =a+aprint(id(a))#display 140123195676424print(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]
?
轉(zhuǎn)載于:https://www.cnblogs.com/lcl0421/p/8145572.html
總結(jié)
以上是生活随笔為你收集整理的python中+=和=+的区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matplotlib绘制饼状图
- 下一篇: Windows环境下安装、卸载Apach