Easy Tutorial
❮ Python Array Rotation Ref Set Intersection_Update ❯

Python int() Function

Python Built-in Functions


Description

The int() function is used to convert a string or a number to an integer.

Syntax

Here is the syntax for the int() method:

class int(x, base=10)

Parameters

Return Value

Returns an integer.


Examples

The following examples demonstrate the use of the int() method:

>>> int()               # Returns 0 when no argument is provided
0
>>> int(3)
3
>>> int(3.6)
3
>>> int('12', 16)        # If base is specified, '12' must be provided as a string, 12 is in hexadecimal
18
>>> int('0xa', 16)  
10  
>>> int('10', 8)  
8

Python Built-in Functions

❮ Python Array Rotation Ref Set Intersection_Update ❯