Python - Numeric Numeric Literals

Introduction

Python provides integers are positive and negative whole numbers.

Python floating-point numbers are numbers with a fractional part.

Python allows us to write integers using hexadecimal, octal, and binary literals.

Python supports a complex number type and allows integers to have unlimited precision.

The following table shows what Python's numeric literals:

Literal Interpretation
1234, -24, 0, 99999999999999 Integers (unlimited size)
1.23, 1., 3.14e-10, 4E210, 4.0e+210 Floating-point numbers
0o177, 0x9ff, 0b101010Octal, hex, and binary literals in 3.X
0177, 0o177, 0x9ff, 0b101010 Octal, octal, hex, and binary literals in 2.X
3+4j, 3.0+4.0j, 3JComplex number literals
set('test'), {1, 2, 3, 4} Sets: 2.X and 3.X construction forms
Decimal('1.0'), Fraction(1, 3)Decimal and fraction extension types
bool(X), True, False Boolean type and constants

Integers are written as strings of decimal digits.

Floating-point numbers have a decimal point and/or an optional signed exponent introduced by an e or E and followed by an optional sign.