Cheatsheet for Simple Things in Python
Format numbers with commas in a print statement
num_to_display = 1000000
print(f'displaying the number with commas {num_to_display:,}')
>>> 1,000,000
Format floats as percentage in a print statement
num_to_display = 10/22
print(f'displaying the number with commas {num_to_display:.2%}')
>>> 45.45%
Format floats with fixed number of decimals in a print statement
num_to_display = 10/22
print(f'displaying the number with commas {num_to_display:.2f}')
>>> 0.45