filmov
tv
Python Comparison: Is vs == (double-equals)

Показать описание
#Python #Shorts
Let's figure out the difference in comparisons when using the "is" operator vs the "==", or double-equals, operator.
When using "is" you are checking that your variables reference the same object. When using "==" you are checking that your objects are identical, meaning they have the same values but they don't have to have the same identity and reference the same memory location.
To figure out the identity for yourself, you can do `print(id(YOUR_VARIABLE))`
-------------------------------------------------------------------------------------
Links:
Let's figure out the difference in comparisons when using the "is" operator vs the "==", or double-equals, operator.
When using "is" you are checking that your variables reference the same object. When using "==" you are checking that your objects are identical, meaning they have the same values but they don't have to have the same identity and reference the same memory location.
To figure out the identity for yourself, you can do `print(id(YOUR_VARIABLE))`
-------------------------------------------------------------------------------------
Links: