Python16 min read
Python Input Output
Learn how to take user input safely, convert types, and print clean output like a professional program.
Emily Davis
July 22, 2025
14.0k649
Input and output are how your program communicates with a user through the terminal.
- **Output**: `print()`
- **Input**: `input()`
## Printing output
```python
print("Hello World")
print("Welcome", "to", "Python")
print("""Line 1
Line 2
Line 3""")
```
Expected output:
```
Hello World
Welcome to Python
Line 1
Line 2
Line 3
```
## Getting user input
```python
name = input("What's your name? ")
print(f"Hello {name}!")
```
Example:
```
What's your name? Rachel
Hello Rachel!
```
## Very important concept: input() returns a string
Even when a user types `20`, Python reads it as text.
```python
age_text = input("Enter your age: ")
print(type(age_text))
```
Example:
```
Enter your age: 20
<class 'str'>
```
So you convert:
```python
age = int(age_text)
```
## Type conversion example with logic
```python
age = int(input("Enter your age: "))
if age >= 18:
print("You're an adult.")
else:
print("You're under 18.")
```
Example:
```
Enter your age: 15
You're under 18.
```
## Print formatting: sep and end
```python
print("apple", "banana", "cherry", sep=", ")
print("Loading", end="...")
print("Done!")
```
Expected output:
```
apple, banana, cherry
Loading...Done!
```
## Graph: input to output
```mermaid
flowchart TD
A[input()] --> B["string value"]
B --> C[int()/float() if needed]
C --> D[logic]
D --> E[print output]
```
In the next lesson, you will learn file handling so your program can save and read information from disk.
#Python#Beginner#I/O