Is there a difference between `==` and `is` in python?
- by Bernard
My Google-fu has failed me.
In Python, are these:
n = 5
# Test one.
if n == 5:
print 'Yay!'
# Test two.
if n is 5:
print 'Yay!'
two tests for equality equivalent (ha!)? Does this hold true for objects where you would be comparing instances (a list say)?
Okay, so this kind of answers my question:
l = list()
l.append(1)
if l == [1]:
print 'Yay!'
# Holds true, but...
if l is [1]:
print 'Yay!'
# Doesn't.
So == tests value where is tests to see if they are the same object?