真值与空值
# 以下在条件判断中均为 False:0, 0.0, '', [], {}, set(), None
短路逻辑
a = None b = a or "default" # 左侧为假,返回右值 c = a and 100 # 左侧为假,直接返回左值(None)
any/all
nums = [0, 1, 2] print(any(nums), all(nums)) # True, False
转载请注明:周志洋的博客 » Python基础知识-布尔与逻辑运算
# 以下在条件判断中均为 False:0, 0.0, '', [], {}, set(), None
a = None b = a or "default" # 左侧为假,返回右值 c = a and 100 # 左侧为假,直接返回左值(None)
nums = [0, 1, 2] print(any(nums), all(nums)) # True, False
转载请注明:周志洋的博客 » Python基础知识-布尔与逻辑运算