Python第二次课20150319.pptVIP

  • 47
  • 0
  • 约6.89千字
  • 约 45页
  • 2016-12-13 发布于重庆
  • 举报
(三)简单条件构造(关系运算符的使用) 3 4 True 3 * 4 3 + 4 False hello == hello True hello hello False Hello hello True (四)复杂条件的构造 分支和循环结构中都有可能需要使用较为复杂的条件进行控制 仅使用关系运算符无法表达一些完整信息 例如:闰年的判断 字母字符的判断 需要借助于布尔操作符构造出复杂条件 布尔操作符 布尔操作符: and,or和 not 布尔运算符and和or用于组合两个布尔表达式,并产生一个布尔结果 expr and expr expr or expr not运算符计算一个布尔表达式的反 not expr 布尔操作结果 P Q P and Q P or Q not P True True True True False True False False True False False True False True True False False False False True 布尔操作符 a or not b and c Python中布尔操作符的优先级,从高分到低分依次是not、and最低是or。所以上面的达式等于如下这个带括号的版本: (a or ((not b) and c)) 例如:闰年

文档评论(0)

1亿VIP精品文档

相关文档