Python Docs

User Input

Python allows for user input.

That means we are able to ask the user for input.

The following example asks for your name, and when you enter a name, it gets printed on the screen:

Example

Ask for User Inpute :

print("Enter your name:")
name = input()
print(f"Hello {name}")

Output:

Enter your name:
xyz
Hello xyz

Using prompt :

In the example above, the user had to input their name on a new line.
The Python input() function has a prompt parameter, which acts as a message you can put in front of the user input, on the same line:

Example

Add a message in front of the user input :

name = input("Enter your name: ")
print(f"Hello {name}")

Output:

Enter your name:
Hello xyz

Multiple Inputs

You can add as many inputs as you want, Python will stop executing at each of them, waiting for user input:

Example

Multiple inputs :

name = input("Enter your name: ")
print(f"Hello {name}")
fav1 = input("Enter your first favorite color: ")
fav2 = input("Enter your second favorite color: ")
print(f"Your favorite colors are {fav1} and {fav2}")

Output:

Enter your name: xyz
Hello xyz
Enter your first favorite color: Purple
Enter your second favorite color: Black
Your favorite colors are Purple and Black