+ 1
A python doubt
sex = "F" if sex == "M" or "m": print("Male") else: print("Female") This prints Male How it is possible
5 odpowiedzi
+ 11
QUANTUMSPARK1 In python, strings are always evaluated true except empty string :)
+ 13
Because you're not comparing "m" to anything, therefore it is naturally a true expression.
Your code needs to be like this,
sex = "F"
if sex == "M" or sex == "m":
print("Male")
else:
print("Female")
+ 6
Simba Not only string even if you write number or float value in if statement it will evaluate true.
if 10: // true
print (11)
else:
print (12)