The following if
test will always evaluate as true:
if animal=="Dog" or "dog":
To above works as if it had the parentheses:
if (animal=="Dog") or ("dog"):
The second part of the or
will, under Python rules, always evaluate to True: non-empty strings have boolean value of True.
Here are three options that work:
if animal=="Dog" or animal == "dog":
if animal in ("Dog", "dog"):
if animal.lower() =="dog":
MORE: These issues can be easily tested on python's handy interactive command prompt. For example, observe the boolean value of "Dog"
and ""
:
>>> bool("Dog"), bool("")
(True, False)
And, here is the combined statement:
>>> bool('Cat' == 'Dog' or 'dog')
True