My Python Cheatsheet
Print
# concatenate with +
>>> import os
>>> print('Hello, ' + os.getlogin() + '! How are you?')
Hello, daniel.guo! How are you?
>>> import os
>>> print(f"Hello, {os.getlogin()}! How are you?")
Hello, daniel.guo! How are you?
Variables
# dynamic typed
>>> m = 0
>>> n = "abc"
# multiple assignments
>>> m, n, z = 0, "abc", False
>>> x = None
# Increment
>>> n = 10
>>> n = n + 1
>>> n += 1
If-else
# parentheses or curly braces are not required
x = 10
if x % 2 == 0:
n += 1
elif x % 5 == 0:
n += 2
else:
n += 3