You're correct that == and is are not the same thing. However, that code does indeed work as I posted (I tested it). Strings are immutable, meaning that richestDuck is "Scrooge McDuck" evaluates to True on the basis that richestDuck is bound directly to the immutable string literal "Scrooge McDuck".
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks, Jason for this amazing series -- I minor correction. I think this output of this code isn't accurate
richestDuck = "Scrooge McDuck"
if richestDuck is "Scrooge McDuck":
print("I am the richest duck in the world!")
if richestDuck is not "Glomgold":
print("Please, Glomgold is only the SECOND richest duck in the world.")
it should only produce:
You're correct that
==
andis
are not the same thing. However, that code does indeed work as I posted (I tested it). Strings are immutable, meaning thatrichestDuck is "Scrooge McDuck"
evaluates toTrue
on the basis thatrichestDuck
is bound directly to the immutable string literal"Scrooge McDuck"
.