Suppose I have this code:
JavaScript
x
4
1
a = 0
2
if a == 0 or a > 0:
3
print(a)
4
That is: I want to do something when a
is not negative.
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 supported:
JavaScript
1
6
1
>>> if a !< 0:
2
File "<stdin>", line 1
3
if a !< 0:
4
^
5
SyntaxError: invalid syntax
6
Why is this syntax invalid? What can I use instead to simplify the conditional?
Advertisement
Answer
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.