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:
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
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://198.211.115.131/python/built-in-function/int.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics