Python Tip of the Day: Know the Difference Between == and is
Know the Difference Between ==
and is
Author: Jeremy Morgan
Published: November 16, 2024
I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.
==
checks if values are equal, while is
checks if they are the exact same object.
# Comparing objects
a = [1, 2, 3]
b = a
c = [1, 2, 3]
print(a == c) # Output: True
print(a is c) # Output: False
print(a is b) # Output: True
The Python Tip of the Day is a daily series published in the month of November. The tips are designed to help you become a better Python programmer. I post tips like this and more every single day on X. Let’s connect!
I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.