python_numeric_literals_and_creation

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.

python_numeric_literals_and_creation.txt · Last modified: 2024/04/28 03:21 by 127.0.0.1