Python int() Function
Description
The int() function is used to convert a string or number to an integer type.
Syntax
The following is the syntax of the int() method:
class int(x, base=10)
Parameters
- x -- A string or number.
- base -- The base number, decimal by default.
Return Value
Returns integer data.
Examples
The following shows examples of using the int() method:
>>>int() # When no argument is passed, the result is 0
0
>>> int(3)
3
>>> int(3.6)
3
>>> int('12',16) # If the base parameter is provided, 12 should be input as a string; 12 is in hexadecimal
18
>>> int('0xa',16)
10
>>> int('10',8)
8
Python Built-in Functions