w3resource

Python: int() function

int() function

The int() function converts the specified value into an integer number.

The int() function returns an integer object constructed from a number or string x, or return 0 if no arguments are given.

Version:

(Python 3.2.5)

Syntax:

int(x=0)
int(x, base=10)

Parameter:

Name Description Required /
Optional
x A number or string to be converted to integer object. Default argument is zero. Required
base Number format. Default value: 10. Optional

Return value:

If x is a number, return x.__int__().

Example: Python int() function

# integer
print("int(225) is:", int(225))

Output:

int(225) is: 225

Pictorial Presentation:

Python: Built-in-function - int() function

Example: Python int() function with String

# string
print("int('225') is:", int('225'))

Output:

int('225') is: 225

Example: Python int()function with float

# float
print("int(225.25) is:", int(225.25))

Output:

int(225.25) is: 225

Python Code Editor:

Previous: input()
Next: isinstance()

Test your Python skills with w3resource's quiz



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python/built-in-function/int.php