Python 3 – input() function
In Python, we use input() function to take input from the user. Whatever you enter as input, the input function converts it into a string. If you enter an integer value still input() function convert it into a string.
Syntax: input(prompt)
Parameter:
- Prompt: (optional) The string that is written to standard output(usually screen) without newline.
Return: String object
Let’s see the examples:
Example 1: Taking input from the user.
Python3
# Taking input from the userstring = input()# Outputprint(string) |
Output:
geeksforgeeks
Example 2: Taking input from the user with a message.
Python
# Taking input from the username = input("Enter your name")# Outputprint("Hello", name) |
Output:
Enter your name:ankit rai Hello ankit rai
Example 3: By default input() function takes the user’s input in a string. So, to take the input in the form of int you need to use int() along with the input function.
Python3
# Taking input from the user as integernum = int(input("Enter a number:"))add = num + 1# Outputprint(add) |
Output:
Enter a number:15 16
Example 4: Let’s take float input along with the input function.
Python3
# Taking input from the user as floatnum =float(input("Enter number "))add = num + 1# outputprint(add) |
Output:
Enter number 5 6.0
Example 5: Let’s take list input along with the input function.
Python3
# Taking input from the user as listli =list(input("Enter number "))# outputprint(li) |
Output:
Enter number 12345 ['1', '2', '3', '4', '5']
Example 6: Let’s take tuple input along with the input function.
Python3
# Taking input from the user as tuplenum =tuple(input("Enter number "))# outputprint(num) |
Output:
Enter number 123
('1', '2', '3')
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


