The difference between pythonis and ==:
##is is used to determine two variable references Whether the objects are the same, == is used to determine whether the values of reference variables are equal.
a is b is equivalent to id(a)==id(b), id() can obtain the memory address of the object. (Recommended learning:Python video tutorial)
If a=10;b=a; then the memory addresses of a and b are the same at this time;But when a =[1,2,3]; When b=a[:], although the values of a and b are the same, the memory addresses are different. If you define a=10, b=10 at this time, and then compare a is b, you will find that the returned result is True. This is because a small shaping pool will be created in Python with a range of [ -5,256] to open up memory space for these integers. When integers within this range are defined in the code, the memory address will not be reallocated.And I tested it in Pycharm:
#coding=utf-8 a=100000000000; b=100000000000; print a is b
The result:
True
Python Tutorial column to learn!
The above is the detailed content of The difference between python is and ==. For more information, please follow other related articles on the PHP Chinese website!