r/backtickbot • u/backtickbot • Jun 12 '21
https://np.reddit.com/r/learnpython/comments/nxzxgk/what_is_the_difference_between_is_and/h1jt8jt/
If you had tried coding in JavaScript, there is a '===' comparison operator. What's the difference of === and ==?
The answer is simple:
==compares both of the objects' values. Returns atrueboolean value if both have the same value, regardless of data type.===compares both of the objects values and data types. Returns a true boolean value if both have the same value and data types.
Since JavaScript is a dynamically-typed language, he has to implement type comparison. Same goes for Python, except replacing === with is.
If we have some float x and int y with similar values (assumed to be 69, nice), then:
x is y
>>> False
x == y
>>> True
1
Upvotes