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

后端 未结 4 1323
无人共我
无人共我 2021-01-13 16:07

Consider a following snippet:

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

Essentially, I want to do something when a is not nega

相关标签:
4条回答
  • 2021-01-13 16:22

    I was surprised to see that this particular operation does not exist in Python!

    I'm not familiar with any language that does have this operator. It is simply not needed.

    As for your snippets:

    if a == 0 or a > 0

    It is exactly the same as if a >= 0

    0 讨论(0)
  • 2021-01-13 16:24

    You can use the equal or greater than operator:

    if a >= 0:
        print(a)
    
    0 讨论(0)
  • Well python !> doesn't work.But

    if not a > 70:
    
        print(' The number is Not bigger than 70')
    
    else:
        print(' The number is DEFINITELY bigger than 70')
    

    this surprisingly works

    0 讨论(0)
  • 2021-01-13 16:45

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

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

    0 讨论(0)
提交回复
热议问题