Raw strings
Raw strings prints any backslash in the string.
print('That\'s my cat')
print(r'[a-z\'A-Z]')
Interpolation
You don't have to use str() to convert values to string.
name = 'John'
age = 40
message = 'My name is %s and I\'m %s old'
print(message % (name, age))
print("I am %s and have %s dogs " % ("John", 2))
F-String
In a f-string braces are used insteed of %s
name = 'John'
age = 40
message = f'My name is {name} and I\'m {age} old'
print(message)
print('My name is {} and I am {} old'.format(name, age))
print('My name is {0}'.format(name, age))
Format Decimals
A = [1, 2, 3]
avg = sum([1, 3])/len([1,3])
print(f"{avg:.2f}")
Strip
Strip off whitespace characters (\s, \t, \n)
HELLO = ' Hello World '
HELLO_STRIP = HELLO.strip()
HELLO_LSTRIP = HELLO.lstrip()
HELLO_RSTRIP = HELLO.rstrip()
assert f'x{HELLO_STRIP}x' == 'xHello Worldx'
assert f'x{HELLO_LSTRIP}x' == 'xHello World x'
assert f'x{HELLO_RSTRIP}x' == 'x Hello Worldx'