- The Python Apprentice
- Robert Smallshire Austin Bingham
- 128字
- 2021-07-02 22:17:02
Reassigning a reference
Now we'll modify the value of x with another assignment:
>>> x = 500
This does not result any sort of change to the int(1000) object we previously constructed. Integer objects in Python are immutable and cannot be changed. In fact, what happens here is that Python first creates a new immutable integer object with the value 500 and then redirects the x reference to point at the new object:

Figure 4.2: Reassign the name 'x' to a new integer object with the value 500
Since we have no other references to the original int(1000) object, we now have no way of reaching it from our code. As a result, the Python garbage collector is free to collect it when and if it chooses.
推薦閱讀
- Mastering Zabbix(Second Edition)
- Python數(shù)據(jù)分析基礎(chǔ)
- PyTorch Artificial Intelligence Fundamentals
- C語言程序設(shè)計立體化案例教程
- Windows Presentation Foundation Development Cookbook
- Python高效開發(fā)實(shí)戰(zhàn):Django、Tornado、Flask、Twisted(第2版)
- Redis Essentials
- Python爬蟲、數(shù)據(jù)分析與可視化:工具詳解與案例實(shí)戰(zhàn)
- HTML5開發(fā)精要與實(shí)例詳解
- Managing Microsoft Hybrid Clouds
- RubyMotion iOS Develoment Essentials
- Learning Splunk Web Framework
- Oracle Data Guard 11gR2 Administration Beginner's Guide
- Mastering Bootstrap 4
- 基于MATLAB的控制系統(tǒng)仿真及應(yīng)用