python basis - =, ==, and is

to sum up:

  • =: Is the assignment
  • ==: determining whether is equal, the comparison is a value object, returns True or False
  • is: comparing the memory address of the object, i.e., the comparison is the id value is two objects are the same

 

python caching mechanism, the number of memory address <256 is cached

A =. 1 >>> 
>>> = B. 1 
>>> A == B 
True
 >>> A IS B 
True
>>> A = 257 >>> B = 257 >>> A == B # A, B the values are equal, the memory address is not equal to True >>> a iS B False

>>> id(a)
57320560
>>> id(b)
57323248

 

 

Python three basic elements contained in the object, are: id (identity), type (data type) and value (value)

Guess you like

Origin www.cnblogs.com/wenm1128/p/11557617.html