input()
function is used to take input from user.
Syntax
1
input("Enter your name: ")
Example
1
2
name = input("Enter your name: ")
print("Hello", name)
Type Conversion
1
2
3
4
# input() function always return string
# to convert string to int use int()
age = int(input("Enter your age: "))
print("Your age is", age)
1
2
3
4
5
6
7
8
9
10
11
12
print("Enter your number:")
var = input()
print("You have entered:", var)
# print("After 10 adding:",var + 10) # Error str and int can't added
print("Type of var:", type(var))
print("Correct way to add 10:", int(var) + 10)
# Enter your number:
# 23
# You have entered: 23
# Type of var: <class 'str'>
# Correct way to add 10: 33
Multiple Input
1
2
3
4
# Multiple input
name, age = input("Enter your name and age: ").split()
print("Hello", name)
print("Your age is", age)