Last Updated : 07 Apr, 2025
In Python, we use the 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 converts it into a string.
Python input() Function SyntaxHow input() Function works in Python?Syntax: input(prompt)
Parameter:
- Prompt: (optional) The string that is written to standard output(usually screen) without newline.
Return: String object
In this example, we are using input() function to input user data as a string in Python.
Python
name = input("What is your name? ")
print("Hello, " + name + "!")
Output
What is your name? GFGinput() Function in Python Examples Taking input in Python
Hello, GFG!
In this example, we are using the Python input() function to input user data as a string in Python, which takes input from the user and prints it.
Python
# Taking input from the user
string = input()
# Output
print(string)
Output
geeksforgeeksUser Input in Python
In this example, we are taking input from the user and input user data as a string in Python with a prompt and printing it.
Python
# Taking input from the user
name = input("Enter your name")
# Output
print("Hello", name)
Output
Enter your name:ankit raiConvert User Input to a Number
Hello ankit rai
In this example, we are using the Python input() function which takes input from the user in string format converting it into an integer adding 1 to the integer, and printing it.
Python
# Taking input from the user as integer
num = int(input("Enter a number:"))
add = num + 1
# Output
print(add)
Output
Enter a number:15Take float input in Python
16
In this example, we are using the Python input() function which takes input from the user in string format converts it into float adds 1 to the float, and prints it.
Python
# Taking input from the user as float
num =float(input("Enter number "))
add = num + 1
# output
print(add)
Output
Enter number 5Python Accept List as a input From User
6.0
In this example, we are taking input from the user in string format converting it into a list, and printing it.
Python
# Taking input from the user as list
li =list(input("Enter number "))
# output
print(li)
Output
Enter number 12345Take User Input for Tuples and Sets
['1', '2', '3', '4', '5']
In this example, we are taking input from the user in string format converting it into a tuple, and printing it.
Python
# Taking input from the user as tuple
num =tuple(input("Enter number "))
# output
print(num)
Output
Enter number 123Input with a dictionary comprehension
('1', '2', '3')
In this example, we are taking the words separated by space to input user data as a string in Python, and we make a dictionary of the word as the key with their length as the value.
Python
words_str = input("Enter a list of words, separated by spaces: ")
words = {word: len(word) for word in words_str.split()}
print(words)
Output
Enter a list of words, separated by spaces: geeks for geeks
{'geeks': 5, 'for': 3}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4