Chapters
Python114 chapters

ReferenceBuilt-in functions

int()

Converts to a whole number, truncating a float towards zero.

Signature

int(value, base=10)

Parameters

NameMeans
valuea number or a string of digits
basethe base the text is written in

Returns

An int. Raises ValueError if the text is not a whole number.

Example

Python
print(int("42"))
print(int(3.9))
print(int(-3.9))
print(int("ff", 16))

Output

42
3
-3
255

See also