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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
order = input("What will you like to have: ") | |
print("You ordered for " + order) |
OUTPUT:
What will you like to have: pizza
You ordered for pizza
Example 2:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = input("What is your name: ") | |
print("Your name is " + name) |
OUTPUT:
What is your name: Aniket
Your name is Aniket