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

20.19. int(): Convert to int type

To convert a number of a different type to int type, or to convert a string of characters that represents a number:

int(ns)

where ns is the value to be converted. If ns is a float, the value will be truncated, discarding the fraction.

If you want to convert a character string s, expressed in a radix (base) other than 10, to an int, use this form, where b is an integer in the range [2, 36] that specifies the radix.

int(s, b)

Examples:

>>> int(43L)
43
>>> int(True)
1
>>> int(False)
0
>>> int(43.89)
43
>>> int("69")
69
>>> int('77', 8)
63
>>> int('7ff', 16)
2047
>>> int('10101', 2)
21