Python Basics — Day 4(Input & Output in Python)
Aspiring Full-Stack Developer | Python · Django · React · SQL | documenting my learning journey
Building skills in Python and full-stack development, with a focus on web apps and system design
Junior developer in training — Python, Django, React — preparing for a career in full-stack engineering
From Python basics to full-stack projects, sharing my progress as I grow into a developer
Future full-stack engineer | Learning in public: Python, APIs, Databases, and Web Development
Day 4 — Input & Output in Python
01. Output with print()
The print() function displays values on the screen.
When printing multiple values separated by commas, Python automatically adds spaces.
print("Hello")
print("Age:", 25, "years")
# Output: Age: 25 years
02. Input with input()
The input() function receives user input as a string (str).
name = input("Enter your name: ")
print("Hello,", name)
👉 Note: The result of input() is always a string.
To use numbers, you must convert the type.
age = int(input("Enter your age: ")) # str → int
print("Next year you will be", age + 1)
03.f-strings (Formatted Strings)
An elegant way to include variables inside a string.
Add an f before the string and wrap variables inside {}.
name = "Sabin"
age = 35
print(f"My name is {name}, and I am {age} years old.")
📌 You can also format numbers:
pi = 3.141592
print(f"Pi rounded to 2 decimals: {pi:.2f}") # 3.14
04. Multi-line Strings
Use triple quotes """ """ or ''' ''' to print multiple lines.
msg = """Starting Python study!
Today we are learning about input and output.
"""
print(msg)
05.Practice Examples
Example 1: Input + Output
food = input("What is your favorite food? ")
print("Your favorite food is", food, "!")
Example 2: f-string
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(f"{name}, you are {age} years old. Next year you will be {age+1}.")
Example 3: Floating-point Formatting
num = 3.14159
print(f"One decimal place: {num:.1f}")
print(f"Three decimal places: {num:.3f}")