Skip to main content
 首页 » 编程设计

python之Python 中的 bool 运算(文档中的符号)

2024年10月17日7lyhabc

我不是新手程序员,我知道什么是 bool 值以及如何使用它们。问题是,我不太明白 Python 文档中关于 bool 运算的含义:

or_test  ::=  and_test | or_test "or" and_test 
and_test ::=  not_test | and_test "and" not_test 
not_test ::=  comparison | "not" not_test 

所有这些递归意味着什么?为什么在 or_test 中应该有一个“and_test”? 在and_test的描述中关于“not_test”的相同问题 第三行对我来说更没有意义。 任何人都可以指导我完成这些行,以便我最终能够理解这种有点不必要的递归和纠结的符号

请您参考如下方法:

这是更大的 language grammar 的一部分本质上指定了 operator precedence .

这意味着 and 比 or 绑定(bind)得更紧密。请注意,or_test 并不必须包含and,它包含and_test规则 ,它由 not_test 规则或 and_test "and"not_test 构造。 not_test 本身以类似的方式构建,等等。

另见 Notation section引用文档。