Python Basics
Python Console Input
1. What is Console Input?
- Allows the user to type something in the console during program execution
- The program captures what was typed and stores it for use
- Example use case: ask the user their name, then greet them
2. The input() Function
Basic Syntax
input("prompt text: ")
- Takes a single string argument — the prompt shown to the user
- Prints the prompt, then waits for the user to type and press Enter
- Always add a trailing space inside the prompt string for readability
input("Number: ") # ✅ cursor appears after space
input("Number:") # ❌ cursor is smushed against the colon
Storing Input in a Variable
input()returns whatever the user typed — store it in a variable
number = input("Number: ")
print(number) # prints whatever user typed
Input Ends on Enter
- The function keeps waiting until the user presses Enter
- Everything typed before Enter is captured as the value
3. Critical Rule — Input Always Returns a String
- No matter what the user types,
input()always returns astr - Even numbers and booleans come back as strings
value = input("Enter something: ")
print(type(value)) # always <class 'str'>
| User types | Stored as |
|---|---|
6 |
"6" (str) |
3.4 |
"3.4" (str) |
True |
"True" (str) |
Tim |
"Tim" (str) |
To use input as an integer, you must convert it (covered in a future lesson)
4. input() vs print() — Key Difference
print()accepts multiple comma-separated argumentsinput()accepts only ONE argument — passing more causes an error
print("hello", "world") # ✅ works fine
input("hello", "what is your name?") # ❌ TypeError: expected at most 1 argument
5. Using Variables Inside a Prompt — String Concatenation
- To include a variable's value inside an
input()prompt, use+to join strings
name = input("Enter name: ")
age = input("Hello, " + name + ", what is your age? ")
+combines (concatenates) strings into a single string- This works because
nameis already a string (returned byinput())
String concatenation with
+also works insideprint(), not justinput()
6. Multiple Input Statements
input("Press enter to begin...") # no variable needed — just wait for Enter
name = input("Enter name: ")
age = input("Hello, " + name + ", what is your age? ")
print("Hello,", name, "you are", age, "years old!")
- You can use
input()without storing the result if you only need the user to press Enter - Each
input()call pauses the program until the user hits Enter
7. Clearing the Console (Side Guide)
| OS | Command |
|---|---|
| Windows | cls |
| Mac / Linux | clear |
8. Key Takeaways & Recap
input("prompt: ")prints a prompt and waits for the user to press Enter- Always add a trailing space in your prompt string
input()always returns a string — even if the user types a numberinput()takes only one argument — use+concatenation to include variables- String concatenation:
"hello, " + name + "!"joins strings into one - You can chain multiple
input()calls to collect several pieces of data