Input and Output in Python

In this section, we will learn how to take input from the user and hence manipulate it, or simply display it. input() function is used to take input from the user.


1.

#Python program to illustrate getting input from user
name = input("Enter your name: ") 

#user entered the name 'harsh'
print("hello", name)

Output:

hello harsh


2.

#Python3 program to get input from user

#accepting integer from the user the return type of
#input() function is string, so we need to convert the input to integer
num1 = int(input("Enter num1: "))
num2 = int(input("Enter num2: "))

num3 = num1 * num2
print("Product is: ", num3)

Output:

Enter num1:
8

Enter num2:
6

('Product is: ', 48)