python Input
Input is information that a program receives from outside itself. In a beginner python program, input often comes from text that a user types with a keyboard.
Input lets the user give information while the program is running. This makes the program able to receive something instead of only showing fixed results.
What Is python Input?
Think about the direction of the data. If information moves from the user into the program, it is input. If information moves from the program to the user, it is output.
python provides the built-in input() function to read a line of user input. A built-in function is an action python already provides. The next lesson explains input() itself in more detail.
Why Do Programs Need Input?
Without input, a beginner program can only work with information already written into its code. Input gives the program a way to receive information while it runs.
For example, a program may ask for a name, a word, or a choice. The user types the requested information, presses Enter, and the program can continue with the received line.
How Does Input Flow?
When python reaches a basic input() call, it waits for a line of input. The user types characters and presses Enter. python then has the entered line available for the program to use.
The text shown before the user types is often called a prompt. A prompt is a message that tells the user what to enter. A prompt is output; the user's response is input.
| Information | Direction | Type |
|---|---|---|
Enter your name: |
Program → User | Output prompt |
Aisha |
User → Program | Input |
Example
Example 1: Receive a name
Provide Aisha as the program's input:
print(input())
Input to Provide
Aisha
Output
Aisha
Why This Result Appears
The inner input() waits for a line. After Aisha is entered, that text is passed to the surrounding print(), which displays it. This compact form avoids introducing variables before their later lesson.
Example 2: Receive digits as input
Now provide the characters 25 as the input line:
print(input())
Input to Provide
25
Output
25
Why This Result Appears
The program waits until the line 25 is provided. The received line then goes to print(), so the same characters appear as output. Converting input into numeric types is a separate later topic.
Important Input Behavior
- Input moves inward: Data travels from the user or another input source into the running program.
- The program can wait: A basic
input()call pauses while python waits for a line. - Enter finishes the line: In normal keyboard input, the user presses Enter after typing the response.
- Input is not output: What the user supplies and what the program displays have different directions.
Common Mistakes
- Waiting for output while python waits for input: Check whether the program is asking you to type something.
- Forgetting to press Enter: The basic keyboard input line is submitted when you press Enter.
- Confusing the prompt with input: A prompt comes from the program. Your response goes into the program.
- Assuming typed digits are already ready for arithmetic: Input type conversion is handled in its own later lesson.
Short Practice
A program shows Enter city:, and you type Lahore. Which part is input?
Show Answer
Lahore is the input because it moves from you into the program. Enter city: is a prompt sent from the program to you.
FAQ
What is input in python?
Input is information that a python program receives from outside the program. In beginner programs, this often means text typed by a user and submitted by pressing Enter.
How can python receive keyboard input?
python provides the built-in input() function for reading a line of user input. The next lesson explains the input() function in detail.
Does a python program wait for the user when reading input?
Yes. When input() is waiting to read a line, the program pauses there until a line is entered or the input source ends.
Is the text I type input or output?
The text you provide to the program is input. Text the program sends out for you to see is output.
What is the difference between python input and output?
Input moves information into a program. Output moves information out of a program. Thinking about the direction of the data helps you tell them apart.
Summary
python input is information that moves into a running program. A beginner program can use input() to wait for and read a line provided by the user. A prompt is output from the program, while the user's response is input to the program. Remember the direction: input moves in, output moves out. The next lesson focuses on the input() function itself.