all Python 3Input & outputterm
Numeric literals
literals
Python can write numbers in binary (0b), octal (0o) and hexadecimal (0x), allows the _ separator for readability, and supports exponential notation.
Syntax
0b<биты> 0o<цифры> 0x<цифры> <цифры>_<цифры> <число>e<порядок>
All these forms produce a plain int — there is no separate "binary number" type, and it always prints in decimal; to get the prefixed form back use bin(), oct() or hex(), which return strings. Exponential notation is the exception: 1e3 is the float 1000.0, not an int. A leading zero in a decimal literal is a SyntaxError (010); octal needs the explicit 0o prefix.
Examples
print(0b1010) # → 10
print(0o17) # → 15
print(0xFF) # → 255
print(1_000_000) # → 1000000
print(1.5e3) # → 1500.0
print(0b1111 == 15 == 0xF) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy