Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

format binary, octal, hexa numbers

a = 42

text = "{:b}".format(a)
print(text)   # 101010

text = "{:#b}".format(a)
print(text)   # 0b101010

a = 42

text = "{:o}".format(a)
print(text)   # 52

text = "{:#o}".format(a)
print(text)   # 0o52

a = 42

text = "{:x}".format(a)
print(text)   # 2a 

text = "{:#x}".format(a)
print(text)   # 0x2a

text = "{:#X}".format(a)
print(text)   # 0x2A