Suppose I have this code to do something when a
is not negative number:
a = 0
if a == 0 or a > 0:
print(a)
That is: I want to do something when a
is either equal to or greater than 0 (meaning it is not a negative number).
I know that I can write if a != 0:
to check whether a
is not equal to 0
.
So, I tried using if a !< 0:
, following similar logic. However, this is apparently not a valid operator:
>>> if a !< 0:
File "<stdin>", line 1
if a !< 0:
^
SyntaxError: invalid syntax
What can I use to simplify the conditional statement and just say 'if a is not less than 0
'?
Instead of a == 0 or a > 0
, simply use a >= 0
.
See https://docs.python.org/library/stdtypes.html#comparisons for a complete list of available comparison operators.