Python中的“==”、“=”、“is”

“==”

tests whether objects have the same value

>>> 2.0 == 2
True
>>> 2 == 2
True

“=”

Assign values to objects

>>> 2 = 2
  File "", line 1
SyntaxError: can't assign to literal

>>> a = 2
>>> a
2

“is”

tests whether objects have the same identity

>>> 2 is 2
True
>>> 2 is 2.0
False

"Keep your eyes on the stars and your feet on the ground." --西奥多·罗斯福

你可能感兴趣的:(Python3.7)