Python Program to Read Integer as Input (With Example)

In this article, we will learn about python program to read integer as input.

There is a in-built input() function in python3.x to accept user input. It takes input from console entered by user.

input() function returns a string data that can be stored in variable.

If we want to store value in integer variable, we must convert value returned by input() function into integer data type. We can do as below –

int(returned_value)

Example: Read Integer From Console in Python

Using input() function and data-type conversion, we can get input value entered by user in console as below –

# Read integer input from console
n = int(input('Enter a number: '))

When we run above program, output will be –

Enter a number: 22

Here, we have just read input from console entered by user. Entered value in this case is 22.

Now, if we want to print entered value, we can do so using print() function in python.

Print Entered value in Python

We can print entered value as below –

# Read integer input from console
n = int(input('Enter a number: '))

print('Entered value is:', n)

When you run above program, output will be –
Enter a number: 22
Entered value is: 22

Thus, we learnt about python program to read integer as input in python and print it to console. You can also learn how to print “Hello World” in python. Visit official website to learn more.

Leave a Reply