官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 松桃| 榆中县| 灌云县| 柏乡县| 思茅市| 股票| 沙洋县| 鄯善县| 修水县| 库车县| 铜陵市| 西华县| 鹿泉市| 尚志市| 临武县| 罗甸县| 宜川县| 武安市| 台湾省| 太白县| 武山县| 博野县| 岳普湖县| 西乡县| 郴州市| 兴宁市| 民权县| 西充县| 綦江县| 德清县| 平塘县| 亚东县| 商水县| 波密县| 梁平县| 门源| 彩票| 石门县| 福州市| 保康县| 松江区|