The input() function in Python is used to take input from the user during program execution. It allows interaction between the user and the program by accepting data entered through the keyboard.
The data entered by the user is always returned as a string by default.
input(prompt)
str).name = input("Enter your name: ")
print("Hello", name)
Sample Output
Enter your name: Rahul
Hello Rahul
Explanation
name.print().age = input("Enter your age: ")
print(type(age))
Output
<class 'str'>
Explanation
To use numeric values, we need to convert the input.
age = int(input("Enter your age: "))
print(age + 5)
price = float(input("Enter price: "))
print(price * 2)
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print(a + b)
split()a, b = input("Enter two numbers: ").split()
print(int(a) + int(b))
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
sum = num1 + num2
print("Sum =", sum)
input() always returns string dataint(), float()) when neededinput() is used to take user input from the keyboard.