How on earth does the is in Python judge? Ask Daniel for an answer

I entered:

on the command line
a, b = 1, 1
a is b    -sharp True

a, b = 1.1, 1.1
a is b    -sharp True

:
a = 1.1
b = 1.1
a is b    -sharp False  

int:
a = 1
b = 1
a is b:   -sharp True

:
a = 1.1
b = a
a is b:   True

when assigning values to an and b separately, if the value is floating-point, using is to compare two values means that the False int type does not exist
does not understand why

solve the puzzle

Feb.23,2022

1. First of all, about is , as mentioned above, is determines whether the two variables point to the same area of memory, that is, whether the id of the variable is the same.

2. The subject needs to understand the concept of small integer object pool . Because in general, the use of small integers [- 5256] is relatively frequent, python establishes small integer object pool in order to optimize speed, that is to say, these small integers are unique in memory. Therefore:

  https://github.com/leisurelic.

Menu