Does Python support short-circuiting?

后端 未结 3 1969
夕颜
夕颜 2020-11-21 08:47

Does Python support short-circuiting in boolean expressions?

3条回答
  •  礼貌的吻别
    2020-11-21 09:30

    Yes. Try the following in your python interpreter:

    and

    >>>False and 3/0
    False
    >>>True and 3/0
    ZeroDivisionError: integer division or modulo by zero
    

    or

    >>>True or 3/0
    True
    >>>False or 3/0
    ZeroDivisionError: integer division or modulo by zero
    

提交回复
热议问题