布尔操作符 and
、or
、not
布尔操作符有三个,为 and
、or
、not
(而不是C语言的&&、||、!)
优先级从高到低为not
>and
>or
布尔表达式对应布尔运算的规则(就像数字电路的运算规则)
and
<expr> and <expr>
or
<expr> or <expr>
not
not <expr>
条件运算符 ==
==
总是与一个布尔类型的值在比较。
而在Python中,任何表达式都可以被解释为布尔类型
- 数字类型(整数和浮点):
0
->false
,非0
->true
- 序列类型:空序列 ->
false
,非空序列 ->true
在这里response[0]=="y"
为判断,而"Y"
的布尔值始终为1
,所以response[0]=="y" or "Y"
恒为1
,构成死循环。
功能为,直接敲回车(输入为空)时输出vanilla
,有输入时输出为输入值。