Menu Close

Python int() Function

In this tutorial, you will all about Python int() function to convert specified value into a integer number.
int function in Python is a best built-in function to convert specified value into integer. In previous tutorial, we have seen input() function to ask value from the users.

Python int Function

Python int() function in python is a built-in function that is used to convert the specified value into a number integer.


The syntax of python int() function is:-

int(value, base)


int function in python take two parameters.

  • value:- A number or string to be converted into integer number.
  • base:- A number representing the number format, Default value: 10.

Return Value

Return value of int function in python is converted integer number.

Python int() example

Here we will take some examples to understand int function.

Example 1:




Example 2:

Python int function for decimal, octal and hexadecimal.

#Convert binary to int
print(int('101010', 2))

#Convert octal to int.
print(int('0o120', 8))

#Convet hexadecimal to int.
print(int('0xA', 16))



Example 3:

Here we will ask a number from the user using python input() function and then print the table of that number.

num = int(input("Enter a number to print table:- "))
for i in range(1, 11):
	print(f"{num} x {1}:- {i * num}")


Enter a number to print table:- 10
10 x 1:- 10
10 x 1:- 20
10 x 1:- 30
10 x 1:- 40
10 x 1:- 50
10 x 1:- 60
10 x 1:- 70
10 x 1:- 80
10 x 1:- 90
10 x 1:- 100


In this tutorial, you have learned python int() function to convert number to specified value into integer.
If this article help you, please share and keep visiting for further python built-in functions tutorials.

Python built-in functions tutorials

For more information:- Click Here

Python input() Function
Python isinstance() Function

Was this post helpful?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *