Python Tricks

Checking a condition

condition = False

x = 1 if condition else 0

print (x)

Using spaces to easily read large numbers

num1 = 1_000_000_000
num2 = 1_000_000

total = num1 + num2

print(f'{total:,}')

# Output would be:
1,001,000,000

Using context managers

Using enumerate

Using zip to loop over multiple lists

Unpacking

Last updated