Next / Previous / Contents / TCC Help System / NM Tech homepage

6. Numeric types

Python has four types to represent numbers: int, long, float, and complex.

6.1. Integers: int and long types

Values of int and long types represent whole numbers. The int type holds numbers in the range [-2,147,483,648, 2,147,483,647], while the precision of the long type is limited only by the available storage. Starting in version 2.2, Python will automatically switch to long type when it is needed to avoid overflow.

The factory functions used to convert other types to integer types are:

int(n_s)

If n_s is any kind of number, or string containing a number, this function converts it to type int.

int(s, r)

If s is a string representation of a number in base (radix) r , this function converts it to type int.

For example, int("0f", 16) returns 15; int("101", 2) returns 5.

long(n_s)

Converts a number or string to type long.

long(s, r)

Converts a string s representing a number in base r to type long.