Next: Sequence Types Prev: Comparisons Up: Types Top: Top
long
in C, which gives them at least 32
bits of precision. Long integers have unlimited precision. Floating
point numbers are implemented using double
in C. All bets on
their precision are off unless you happen to know the machine you are
working with.
Numbers are created by numeric literals or as the result of built-in
functions and operators. Unadorned integer literals (including hex
and octal numbers) yield plain integers. Integer literals with an `L'
or `l' suffix yield long integers
(`L' is preferred because 1l
looks too much like eleven!).
Numeric literals containing a decimal point or an exponent sign yield
floating point numbers.
Python fully supports mixed arithmetic: when a binary arithmetic
operator has operands of different numeric types, the operand with the
``smaller'' type is converted to that of the other, where plain
integer is smaller than long integer is smaller than floating point.
Comparisons between numbers of mixed type use the same rule.(1)
The functions int()
, long()
and float()
can be used
to coerce numbers to a specific type.
All numeric types support the following operations:
abs(x)
int(x)
long(x)
float(x)
-x
+x
x + y
x - y
x * y
x / y
x % y
x / y
divmod(x, y)
(x / y, x % y)
--- (3)
pow(x, y)
floor
and ceil
in module
math
for well-defined conversions.
[1, 2]
is considered equal
to [1.0, 2.0]
, and similar for tuples.