和/或不保证返回布尔值

当你使用 or 时,如果它是真的,它将返回表达式中的第一个值,否则它将盲目地返回第二个值。即 or 相当于:

def or_(a, b):
    if a:
        return a
    else:
        return b

对于 and,如果为 false 则返回第一个值,否则返回最后一个值:

def and_(a, b):
    if not a:
        return a
    else:
        return b