or operater
- BOOLEAN:
x | y | x or y |
---|---|---|
True | True | True |
True | False | True |
False | True | True |
False | False | False |
True or True => True
False or True => True
True or False => True
False or False => False
x | y | x or y |
---|---|---|
x | y | x, if x is true, otherwise y |
只看or左侧的,如果非空,则返回左侧数值;若空,则直接返回右侧
会返回False的Objects:
- constants defined to be false: None and False.
- zero of any numeric type: 0, 0.0, 0j, Decimal(0), Fraction(0, 1)
- empty sequences and collections: ‘’, (), [], {}, set(), range(0)
0 or 1 => 1
1 or 2 => 1
2 or 1 => 2
[] or 1 => 1
[] or 0 => 0
2 < 4 or [] => True
5 > 10 or [] => []
5 > 10 or 0 => 0
True or 4 < 3 => True
False or 0 < 3 => True