+ 1

How the if statement becomes true in the following code?

sex="F"; if(sex=="m" or "M"): print("male") else: print("female") O/P---->male

13th Jul 2020, 10:13 AM
Keerthivasan J
Keerthivasan J - avatar
2 Réponses
+ 6
Keerthivasan J It becomes true because your "or" condition which as nothing just "M" makes it true. What you did in or isn't comfirm any condition and thus becomes a universal true statement. Therefore it will be always true. And or means anyone condition should be true so 2nd is true and it run that. Also Don't use semicolon ";" in python,it doesn't support as you know. Happy Learning 🙂
13th Jul 2020, 10:49 AM
Ketan [#Be Happy 😄]
Ketan [#Be Happy 😄] - avatar
+ 1
Ketan [#Be Happy 😄] Thank a lot 😁
13th Jul 2020, 10:54 AM
Keerthivasan J
Keerthivasan J - avatar