Python int() Function
Description
The int() function converts a string or number to an integer.
Syntax
The following is the syntax of the int() method:
class int(x, base=10)
Parameters
- x -- a string or number.
- base -- the base of the number, decimal by default.
Return Value
Returns integer data.
Example
The following examples demonstrate the use of 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 must be entered as a string, where 12 is hexadecimal
18
int
(
'
0xa
'
,
16
)
10
int
(
'
10
'
,
8
)
8
Python built-in function