Skip to main content

Command Palette

Search for a command to run...

Python Basics — Day 4(Input & Output in Python)

Updated
2 min read
S

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}")

Python Basics

Part 4 of 21

A collection of study notes from my university and self-learning journey. This series covers Python fundamentals step by step — from setup to core concepts — to help both myself and others build a solid foundation in coding.

Up next

Python Basics — Day 5 Conditional Statements (if / elif / else)

1️⃣ Basic if Statement Code inside the block runs only if the condition is True. age = 20 if age >= 18: print("You are an adult.") # Condition is True → executed ⚠️ Note: Indentation matters! In Python, 4 spaces are recommended. 2️⃣ if ~ e...

More from this blog

S

Sabin’s DevLog

21 posts

I plan to upload everything I study and prepare here. I hope it can be helpful to others, and I also want my future self to see the learning journey I’ve been through.