==
and is
¶The rule of thumb to when to use ==
or is
.
==
is for value equality. Use to know if two objects have the same value.is
is for reference equality. Use to know if two references refer to the same object.OR more compactly;
is
- identity testing,==
- equality testing.a = [1, 2, 3]
b = a
b is a
True
b == a
True
b = a[:]
b is a
False
b == a
True
# Also and most annoyingly;
print([] is [])
print([] == [])
False True
while
statement¶def funzo():
contin = input("Are you having fun yet?(Y/N) ")
while contin == "N":
contin = input("I'm sorry! :( \n Are you having fun now? (Y/N) ")
while contin == "Y":
return "Good! I hope your happy now."
funzo()
Are you having fun yet?(Y/N) N I'm sorry! :( Are you having fun now? (Y/N) N I'm sorry! :( Are you having fun now? (Y/N) N I'm sorry! :( Are you having fun now? (Y/N) Y
'Good! I hope your happy now.'