- The Python Apprentice
- Robert Smallshire Austin Bingham
- 139字
- 2021-07-02 22:17:03
Assigning one reference to another
When we assign from one variable to another, what we're really doing is assigning from one object reference to another object reference, so that both references then refer to the same object. For example, let's assign our existing variable x to a new variable y:
>>> y = x
That gives us this resulting reference-object diagram:

Figure 4.3: Assign the existing name 'x' to the name 'y'
Now both references refer to the same object. We now reassign x to another new integer:
>>> x = 3000
Doing this gives us a reference-object diagram showing our two references and our two objects:

Figure 4.4: Assign a new integer 3000 to 'x'
In this case there is no work for the garbage collector to do because all of the objects are reachable from live references.
推薦閱讀
- iOS Game Programming Cookbook
- Facebook Application Development with Graph API Cookbook
- 高手是如何做產品設計的(全2冊)
- C語言程序設計教程(第2版)
- Servlet/JSP深入詳解
- Python零基礎快樂學習之旅(K12實戰訓練)
- Blockly創意趣味編程
- The Complete Coding Interview Guide in Java
- Flutter跨平臺開發入門與實戰
- Getting Started with React Native
- C++20高級編程
- Learning JavaScript Data Structures and Algorithms(Second Edition)
- PHP 8從入門到精通(視頻教學版)
- Android 游戲開發大全(第二版)
- Clojure for Finance