Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an operation for not less than or not greater than in python?

Consider a following snippet:

a = 0
if a == 0 or a > 0:
    print(a)

Essentially, I want to do something when a is not negative. If instead of this, I had wanted to do something when a is not 0, I would have simply written:

if a != 0 :

In the same spirit, I tried :

if a !< 0 :

assuming the consistency of the Python where user starts guessing the correct implementations once he/she gets used to the language. I was surprised to see that this particular operation does not exist in Python! My question is that why such simple thing has not been implemented in Python and is there another way in which it has been implemented. Any feedback is highly appreciated. Thank you

like image 678
Peaceful Avatar asked Nov 28 '22 20:11

Peaceful


1 Answers

Instead of a == 0 or a > 0 you could just use a >= 0.

https://docs.python.org/library/stdtypes.html#comparisons

like image 86
Michael Zhang Avatar answered Dec 04 '22 05:12

Michael Zhang