Python Numeric Literals and creation

Literals and creation

Numbers are written in a variety of numeric literal forms, and created by some built-in operations:

1234, −24, +42, 0

Integers (unlimited precision).[1]

1.23, 3.14e-10, 4E210, 4.0e+210, 1., .1

Floating-point (normally implemented as C doubles in CPython).

0o177, 0x9ff, 0b1111

Octal, hex, and binary literals for integers.[2]

3+4j, 3.0+4.0j, 3J

Complex numbers.

decimal.Decimal(‘1.33’), fractions.Fraction(4, 3)

Module-based types: decimal, fraction.

int(9.1), int(‘-9’), int(‘1111’, 2), int(‘0b1111’, 0),

float(9), float(‘1e2’), float(‘-.1’), complex(3, 4.0)

Create numbers from other objects, or from strings with possible base conversion. Conversely, hex(N), oct(N), and bin(N) create digit strings for integers, and string formatting makes general strings for numbers. See also String formatting, Type Conversions, and Built-in Functions.

Fair Use Source: B00HZ41PGC