How do boolean operators work in 'if' conditions?
I am currently new to Python and am trying to run a few simple lines of
code. I cannot understand how Python is evaluating this syntax after the
if statement. Any explanations will be appreciated.
number = int(raw_input("Enter number : "))
if number == (1 or 2 or 3):
print "Match"
else:
print "No match"
Only the integer 1 yield a positive result and any other numbers including
2 and 3 go through the else branch. Can the conditions be stated as the
following only?:
if number == 1 or number == 2 or number == 3:
Thank you.
No comments:
Post a Comment