Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python int() Function

Python int() Function

Python built-in function Python built-in 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

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 Python built-in function