相关疑难解决方法(0)

Python - "if"语句中的逻辑评估顺序

在Python中我们可以这样做:

if True or blah:
    print("it's ok") # will be executed

if blah or True: # will raise a NameError
    print("it's not ok")

class Blah:
    pass
blah = Blah()

if blah or blah.notexist:
    print("it's ok") # also will be executed
Run Code Online (Sandbox Code Playgroud)
  • 有人能指出我有关此功能的文档吗?
  • 它是语言的实现细节还是功能?
  • 利用此功能是不是很好的编码风格?

python boolean short-circuiting

9
推荐指数
2
解决办法
1万
查看次数

标签 统计

boolean ×1

python ×1

short-circuiting ×1