iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 6
0
自我挑戰組

Python 自學歷程分享系列 第 6

可變和不可變物件

1.不可變物件(int, string, float, tuple),如果資料改變,會複製一份資料到新的記憶體空間然後資料更新,像下圖這樣:
https://ithelp.ithome.com.tw/upload/images/20181009/201121409tN00z9dOX.png
執行後的結果:
https://ithelp.ithome.com.tw/upload/images/20181009/20112140HtTx14RgaB.png
2.可變物件(list, dict, set),如果資料改變則直接在指向的記憶體空間改變資料,下圖是一個簡單的範例:
https://ithelp.ithome.com.tw/upload/images/20181009/20112140phSgZ5NgjY.png
執行完的結果就是這樣:
https://ithelp.ithome.com.tw/upload/images/20181009/20112140zwah98NYRi.png


上一篇
Python中的簡單資料型別
下一篇
字串-1
系列文
Python 自學歷程分享30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言