0

Why am I getting the output as "hello" why not "bey" because "a" value is not equal to either "A" or "a"

a = "H" if a == "A" or "a": print("hello") else: print("bey")

14th Jul 2021, 1:56 AM
Shahir
Shahir - avatar
2 odpowiedzi
+ 4
You need to use; if a == "A" or a == "a": or "a" will return a truthy result as a non-empty string is truthy. You need to have an expression on each side of an 'or'/'and' that can be evaluated.
14th Jul 2021, 2:14 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
because you must write: if a == "A" or a == "a": alternativaly you could write too: if a in "Aa":
14th Jul 2021, 2:12 AM
visph
visph - avatar