In JavaScript, one could do this:
if (integer > 3 && integer < 34){
document.write("Something")
}
Is this possible in Python?
In JavaScript, one could do this:
if (integer > 3 && integer < 34){
document.write("Something")
}
Is this possible in Python?
Python indeed allows you to do such a thing
if integer > 3 and integer < 34
Python is also smart enough to handle:
if 3 < integer < 34:
# do your stuff
Python replaces the usual C-style boolean operators (&&
, ||
, !
) with words: and
, or
, and not
respectively.
So you can do things like:
if (isLarge and isHappy) or (isSmall and not isBlue):
which makes things more readable.
Just on formatting. If you have very long conditions, I like this way of formatting
if (isLarge and isHappy) \
or (isSmall and not isBlue):
pass
It fits in nicely with Python's comb formatting
Yes, it is:
if integer > 3 and integer < 34:
document.write("something")