Solved
if color == "red" or "blue" is always True
OP
edited
Took me ages: if color == "red" or "blue": runs even when color is "green".
Comments 5
Log in to join the discussion.
Log in Create accountPython reads it as
(color == "red") or ("blue"). A non-empty string is truthy, so the whole thing is always True.Write either:
The second is the Pythonic way.
The
inversion is so much nicer.One of the most common beginner bugs in every language that allows truthy strings. You're in good company.
oralso returns one of its values, not just True/False:name = user_input or "Anonymous"is a neat default.Careful with that default trick when 0 is a valid input though.