Way to determine if X and Y are both over 0

前端 未结 2 1797
隐瞒了意图╮
隐瞒了意图╮ 2021-01-29 10:41

I was wondering if there was a way of telling if two numbers were both above 0. I was thinking of using an elif statement but I wasn\'t sure if that would work.

相关标签:
2条回答
  • 2021-01-29 11:03

    Use boolean operators to test more than one condition, here the and operator does what you want:

    if x > 0 and y > 0:
        # x and y are both over 0.
    
    0 讨论(0)
  • 2021-01-29 11:06

    Just for fun, here's another method:

    if min(x, y) > 0:
        # x any y are both over 0
    
    0 讨论(0)
提交回复
热议问题