How to use the input() function for user input in Python

Overview

We use the input() function in python to obtain the user input. The name of the input() function itself means that it allows the user to give input.

Syntax

input(prompt)

Parameter

prompt: A string representing a message before the input.

Example

print('Enter your Country:')
x = input()
print(x)

Enter the input below

Explanation

  • The code above shows how we can apply input() function to get user input. The input is stored in a variable x . The variable x is then printed in line 3 to show the input.

Example

x = input("Please enter your name: ")
print("Hello, " + x )
print(" Welcome to Educative.")

Enter the input below

Explanation

  • Line 1: We call the input() function along with the prompt parameter.
  • Line 2–3: We print the input along with other messages.

Free Resources