"is" vs "==" in Python – What's the Difference? (And When to Use Each)
https://dbader.org/python-tricks ► Write clean & Pythonic code and start using advanced features in your Python code
It’s easy to get tripped up by Python’s “is” and “==” operators for object comparison. In this video I’ll explain the difference with a few easy to understand examples.
There’s a difference in meaning between equal and identical. And this difference is important when you want to understand how Python’s is and == comparison operators behave.
The == operator compares by checking for equality – the “is” operator, however, compares identities.
The difference between them breaks down to down to two short definitions:
An is expression evaluates to True if two variables point to the same (identical) object.
An == expression evaluates to True if the objects referred to by the variables are equal (have the same contents).
Check out this tutorial if you want to drill deeper: https://dbader.org/blog/difference-between-is-and-equals-in-python
SUBSCRIBE TO THIS CHANNEL: https://dbader.org/youtube
* * *
► Python Developer MUGS, T-SHIRTS & MORE: https://nerdlettering.com
FREE Python Tutorials & News:
» Python Tutorials: https://dbader.org
» Python News on Twitter: https://twitter.com/@dbader_org
» Weekly Tips for Pythonistas: https://dbader.org/newsletter
» Subscribe to this channel: https://dbader.org/youtube