Important Python Concept

User Input in Python

Any information or data sent to an application for processing is considered user input.
Eg – app taking orders, taking photos, etc.

In python, we as developers can ask the user for input.


Note: in python 2.7, we used raw_input() for taking user input but now, in python 3.7+, we use input().

 

Practical Example

 

Assuming we have an online restaurant application, we need to ask our users, what will they like to have.

 
What will you like to have: pizza
You ordered for pizza

To create the above application, we need to take user input in Python.

 

Syntax for User Input in Python

 
Variable_name = input("Prompt")
 
Example 1:

 

order = input("What will you like to have: ")
print("You ordered for " + order)
view raw input1.py hosted with ❤ by GitHub

 

OUTPUT:
What will you like to have: pizza
You ordered for pizza
 
Example 2:

 

name = input("What is your name: ")
print("Your name is " + name)
view raw input2.py hosted with ❤ by GitHub

 

OUTPUT:
What is your name: Aniket
Your name is Aniket
 
Aniket Malik

Aniket Malik

CERTIFIED TUTOR/TRAINER WITH 300+ REVIEWS

Facing difficulty with

this concept?