"is" vs "==" in Python – What's the Difference? (And When to Use Each)
73.1 هزار بار بازدید -
8 سال پیش
-
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-be...
FREE COURSE – "5 Thoughts on Mastering Python" https://dbader.org/python-mastery
PYTHON TRICKS: THE BOOK https://dbader.org/pytricks-book
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: Twitter: @dbader_org
» Weekly Tips for Pythonistas: https://dbader.org/newsletter
» Subscribe to this channel: https://dbader.org/youtube
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-be...
FREE COURSE – "5 Thoughts on Mastering Python" https://dbader.org/python-mastery
PYTHON TRICKS: THE BOOK https://dbader.org/pytricks-book
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: Twitter: @dbader_org
» Weekly Tips for Pythonistas: https://dbader.org/newsletter
» Subscribe to this channel: https://dbader.org/youtube
8 سال پیش
در تاریخ 1395/10/07 منتشر شده
است.
73,102
بـار بازدید شده