A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python-3-input-function/ below:

Python 3 - input() function

Python 3 - input() function

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 Syntax

Syntax: input(prompt)

Parameter:

Return: String object

How input() Function works in Python?

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? GFG
Hello, GFG!
input() Function in Python Examples Taking input in Python

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

geeksforgeeks
User 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 rai
Hello ankit rai
Convert User Input to a Number

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:15
16
Take float input in Python

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 5
6.0
Python Accept List as a input From User

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 12345
['1', '2', '3', '4', '5']
Take User Input for Tuples and Sets

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 123
('1', '2', '3')
Input with a dictionary comprehension

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