Python compares two objects for equality in two ways, and simply, they differ as follows:
1,is is a comparison of two references that point to the same object (reference comparison)
2,== is a comparison of the values of two objects for equality.
>>>a = [2,3,4]>>>b = a is atrue# Tile operation reassigned Object is Afalse # The values are equal True
Implementation principle
is to compare whether the two are the same object, compared with memory addresses (ID is equal).
= = is a value comparison, an immutable object, such as INT,STR, which directly compares values. For Python-known objects, the __sq__ function is called to compare.
Object caching mechanism
Python will be relatively small object cache, the next time you use, go back to the buffer to find, if found, do not go back to open up new memory, but continue to assign the address of the small object to the new value
1 c = 12 d = 13print is d)4True5 6 is 10**37False8 -= = 10**39 True
The computed assignment does not use a buffer.
Python "is" and "= ="