Formatting big integers – Python 3.6+
a = 1000000000# not easy to see right?# let's make it easiera = 1_000_000_000# You can group numbers as you likeb = 1_0_9_0Grouping Hexadecimal and bits
# grouping hexadecimal addresses by wordsaddr = 0xCAFE_F00D# grouping bits into nibbles in a binary literalflags = 0b_0011_1111_0100_1110Lib pathlib to manipulate system’s path
from pathlib import Pathpath = Path("some_folder")print(path)# output: some_folder# We can add more subfolders in a readable waypath = path / "sub_folder" / "sub_sub_folder"print(path)# output: some_folder/sub_folder/sub_sub_folder# make path absoluteprint(path.resolve())# output: /Users/r.orac/some_folder/sub_folter/sub_sub_folderString Format with interpolation – Python 3.6+
person = 'roman'exercise = 0print(f"{exercise}-times {person} exercised during corona epidemic")# output# 0-times Roman exercised during corona epidemicprint(f"{exercise+1}-times {person} exercised during corona epidemic")# Output# '1-times roman exercised during corona epidemic'f = 0.333333print(f"this is f={f:.2f} rounded to 2 decimals")# Outputthis is f=0.33 rounded to 2 decimals
Post a Comment