DEV Community

Discussion on: Dead Simple Python: Data Typing and Immutability

Collapse
 
ammaralim profile image
Ammar Alim • Edited

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.")

I am the richest duck in the world!
Please, Glomgold is only the SECOND richest duck in the world.

it should only produce:

Please, Glomgold is only the SECOND richest duck in the world.
since == isn't the same as "is"

Collapse
 
codemouse92 profile image
Jason C. McDonald

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".