a and bevaluates to a if a is falsey, otherwise it evaluates to b
a or bevaluates to a if a is truthy, otherwise it evaluates to b
- not a evaluates to True if a is falsey, otherwise it evaluates to False
0 and 'Hello' 0
- True is represented as 1, and False is represented as 0.
True == 1
Different Behavior in shell/script
1234e23, 1234e23n1, n2 =
The one line
don't have an else:
if True: print('xxx')
have an else and assign the value:
x = 1 if True else 0
else x = 1.
have an else and don't wanna assign: dirty hack: ignore the returning value:
x = 1 if False else print(0), the print will return None to x.
print(1) if True else print(0), normally do.
ls[:] = [1, 2, 3] To change a list in a function