zoukankan      html  css  js  c++  java
  • and和or运算

      and和or的运算,从前向后按顺序计算,当True结果遇到or就停止,返回True;当False结果遇到and就停止,返回False;False遇到or,继续走;True遇到and,继续走。

    >>> 3 > 2 and 9 > 2 or 7< 9 and 2 < 10    # (3 > 2 and 9 > 2)是True,遇到or后就会直接返回True,or后的表达式不再执行
    True
    
    >>> 3 > 2 and 2 < 5 or 7< 9 and 2 < 10    # (3 > 2 and 2 > 5)是False,遇到or后就会继续向下执行,or后的表达式为True,返回True
    True
    
    >>> 3 < 2 or 2 > 5 and 7< 9 and 2 < 10    # (3 < 2 or 2 > 5)是False,遇到and后就会直接返回False,and后的表达式不再执行
    False
    
    >>> 3 < 2 or 2 < 5 and 7< 9 or 2 < 10 and 10 > 1    # (3 < 2 or 2 < 5)是True,遇到and后就会继续向下执行,遇到or返回True,or后表达式为True,遇到and,继续执行,and后为True,最终返回True
    True

      总结:and和or没有谁先执行或谁后执行,只会按顺序向下执行。

  • 相关阅读:
    算法图解
    Cairo graphics tutorial
    远程对象调用
    异步和多线程的关系
    jQuery调用api
    GTK# tutorial
    DLT
    protobuf入门笔记
    PDO讲解
    数据库练习——分页查询
  • 原文地址:https://www.cnblogs.com/wgbo/p/9580558.html
Copyright © 2011-2022 走看看