1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| """ 在布尔上下文中从左到右演算表达式的值,如果布尔上下文中的所有值都为真,那么 and 返回最后一个值。
如果布尔上下文中的某个值为假,则 and 返回第一个假值。 """
def re(n): return n + 1 and n ** 2
print(re(0)) print(re(100))
"""对于字符串而言,其中有空格的字符串为假,否则为真""" def st(s): return s and s.strip()
print(st('happy ')) print(st('names')) print(st('fa fdaf')) """ 输出结果: 0 10000 happy names fa fdaf """
|