The nature of Python object references

In previous chapters we've already talked about and used "variables" in Python, but what exactly is a variable? Consider something as straightforward as assigning an integer to a variable:

>>> x = 1000

What's really happening when we do this? First, Python creates an int object  with a value of 1000. This object is anonymous in the sense that it doesn't, in and of itself, have a name (x or otherwise). It's simply an object allocated and tracked by the Python runtime system.

After creating the object, Python then creates an object reference with the name x and arranges for x to refer to the int(1000) object:

Figure 4.1:  Assign the name 'x' to an integer object with the value 1000
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset