How to Get User Input in Python

In this Python blog post, I will show how to get user input in Python

The input() function is the go-to tool for this purpose. When invoked, it pauses program execution and prompts the user to enter some data into the command line or terminal window.

Once the user submits their input by pressing “Enter,” input() reads the input as a string and can then be stored in a variable for further processing.

This incredibly versatile function supports a variety of applications, ranging from simple data gathering to complex interactions where user responses dictate subsequent program logic.

For example, developers can use input() to ask for user preferences, retrieve numerical data, or even navigate through different sections of an application based on user choices.

How to Get User Input in Python

The function prompts the user to enter a value. Below, I have two lines of code.

In the first one, I print on the screen and ask the user to enter a message. In the second line, I am using the input() function to get the input from the user.

I can also integrate the input function into a text that prompts input. As shown below, I used it in the first example.

If you need to get the input in the form of a number (int) or float, you will need to convert the value after you receive the input.

Processing…
Success! You're on the list.