Weird things in Python
Short Circuit
a and bevaluates to a if a is falsey, otherwise it evaluates to ba 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
1 | 0 and 'Hello' 0 |
- True is represented as 1, and False is represented as 0.
1 | True == 1 |
Different Behavior in shell/script
1 | n1, n2 = 1234e23, 1234e23 |
The one line if:
don't have an else:
if True: print('xxx')have an else and assign the value:
x = 1 if True else 0can't say
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
1 | def changeLS(ls): |