Formatting big integers – Python 3.6+
a = 1000000000
# not easy to see right?
# let's make it easier
a = 1_000_000_000
# You can group numbers as you like
b = 1_0_9_0
Grouping Hexadecimal and bits
# grouping hexadecimal addresses by words
addr = 0xCAFE_F00D
# grouping bits into nibbles in a binary literal
flags = 0b_0011_1111_0100_1110
Lib pathlib to manipulate system’s path
from pathlib import Path
path = Path("some_folder")
print(path)
# output: some_folder
# We can add more subfolders in a readable way
path = path / "sub_folder" / "sub_sub_folder"
print(path)
# output: some_folder/sub_folder/sub_sub_folder
# make path absolute
print(path.resolve())
# output: /Users/r.orac/some_folder/sub_folter/sub_sub_folder
String Format with interpolation – Python 3.6+
person = 'roman'
exercise = 0
print(f"{exercise}-times {person} exercised during corona epidemic")
# output
# 0-times Roman exercised during corona epidemic
print(f"{exercise+1}-times {person} exercised during corona epidemic")
# Output
# '1-times roman exercised during corona epidemic'
f = 0.333333
print(f"this is f={f:.2f} rounded to 2 decimals")
# Output
this is f=0.33 rounded to 2 decimals