everis very curious,pythonthe variableHow to be so flexible that you don't have to declare their typeand can be a variety of casually assigned value, later in-depth study feel really interesting. Pythonin Digitalstrings, etc.Are objects,1is an object,"Hello"is also an object, each object knows its own type, each object has a reference counter, what is the reference counter to do, add the object"Hello"assigning values to variablesa, namely:a= "Hello"thisais the object "Hello "one of the references, and then putaassign a value tob, i.e.B=a, thenaand thebpoint to the same object"Hello"
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7E/89/wKioL1cDyHmhb_AZAAAW6Z36UU0583.png "title=" Qq20160405221332.png "alt=" Wkiol1cdyhmhb_azaaaw6z36uu0583.png "/>
at this point , the value of the reference counter of Hello is 2 ,python has a garbage collection mechanism, when the reference counter is 0 , the memory occupied by the object is automatically freed. Of course not all objects are like this,Python has a caching mechanism,python caches and re-uses small integers and small strings, such as
>>>a=24
>>>a= "Hello World"
when we assign a new value to a, the object is not recycled as we say, it will probably still be saved in a system table for the next reference, and one more example:
>>>a=45
>>>b=45
>>>a is b
True
at this point , A and B point to the same object .
>>>a=[' A ', ' B ']
>>>b=[' A ', ' B ']
>>>a is b
False
at this point, a,b points to a different object
We can use the is operator to verify thatthe is operator is used to check the identity of the object, and returns True if the two variable names point exactly to the same object. B
we can also query the number of references to Python
>>>import SYS
>>>sys.getrefcount (1)
828
output 828 references, most of which are used by the idle system code.
This variable is not a variable (python variable)