
Open your terminal and type:
python
(On Mac/Linux, use python3)
You will see:
>>>
This is the REPL — Read, Evaluate, Print, Loop.
The REPL is useful for quick experiments and testing small pieces of code. It is not meant for building applications.
Try this:
>>> 2 + 3
5
>>> "hello"
'hello'
To exit the REPL:
>>> exit()
print() is the most basic way to send data from your program to the screen.
print("Hello, World")
Output:
Hello, World
You can print numbers, text, or results of calculations:
print(10)
print(2 + 3)
print("Python is powerful")
print("Score:", 95)
Output:
Score: 95
Python automatically adds a space between values when you separate them with commas.
print(42) # Output: 42
print(3.14) # Output: 3.14
print(True) # Output: True
print(None) # Output: None
print([1, 2, 3]) # Output: [1, 2, 3]
print({"a": 1}) # Output: {'a': 1}
print() is the simplest debugging tool. In real projects, when something behaves unexpectedly, developers add print() statements to check what values variables hold at different points.
Before learning advanced debugging tools, print() is your first line of investigation.
print() has four parameters most people never learn:
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
print("Python", "Java", "C++")
# Output: Python Java C++
print("Python", "Java", "C++", sep=", ")
# Output: Python, Java, C++
print("Python", "Java", "C++", sep=" | ")
# Output: Python | Java | C++
print(2026, 3, 17, sep="-")
# Output: 2026-3-17
By default, print() adds a newline. end changes that.
print("Loading", end="...")
print(" Done!")
# Output: Loading... Done!
print("One", end=" → ")
print("Two", end=" → ")
print("Three")
# Output: One → Two → Three
with open("log.txt", "w") as f:
print("App started", file=f)
print("User logged in", file=f)
Nothing appears in terminal — output goes to log.txt.
Python sometimes holds output in a buffer. flush=True forces it out instantly.
import time
print("Step 1...", flush=True)
time.sleep(1)
print("Step 2...", flush=True)
time.sleep(1)
print("Done!", flush=True)
Each line appears one by one, not all at once.
# Empty line for spacing
print()
# Visual separator
print("=" * 40)
# Output: ========================================
# String repetition
print("Ha" * 5)
# Output: HaHaHaHaHa
# Multi-line output
print("""
==========================
Welcome to Python!
==========================
""")
When a string "looks right" but behaves wrong, repr() shows what's really inside.
text = "Hello\tWorld\n"
print(text)
# Output:
# Hello World
#
print(repr(text))
# Output: 'Hello\tWorld\n'
Tabs (\t) and newlines (\n) become visible. Very useful for debugging.
| What You Want | Code | Output |
|---|---|---|
| Basic output | print("hello") | hello |
| Multiple values | print("a", "b", "c") | a b c |
| Custom separator | print("a", "b", sep="-") | a-b |
| No newline | print("hi", end="") | hi (no line break) |
| Custom ending | print("hi", end="!") | hi! |
| Print to file | print("log", file=f) | (writes to file) |
| Force instant output | print("ok", flush=True) | ok (immediately) |
| Empty line | print() | (blank line) |
| Visual separator | print("=" * 30) | ============================== |
| Repeat string | print("Ha" * 3) | HaHaHa |
| Reveal hidden chars | print(repr(text)) | Shows \n, \t etc. |
print() is not just for displaying output. It is the first debugging tool every developer uses.
You write this:
price = input("Enter price: ")
discount = 20
final = price - (price * discount / 100)
print(f"Final price: {final}")
You enter 500 and get:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Add prints to check what you actually have:
price = input("Enter price: ")
print(f"DEBUG: price = {price}")
print(f"DEBUG: type = {type(price)}")
Output:
DEBUG: price = 500
DEBUG: type = <class 'str'>
price is a string, not a number. Fix it:
price = int(input("Enter price: "))
print() before the broken line — check values and typesEven senior developers do this daily. Before you learn advanced debuggers, print() is all you need.
| Situation | Better Tool |
|---|---|
| Need timestamps and severity levels | logging module |
| Want to pause and inspect variables | pdb debugger |
| Working in VS Code / PyCharm | IDE breakpoints |
We will cover these in later parts. For now, print() is your best friend.
input() pauses the program and waits for the user to type something.
name = input("Enter your name: ")
print("Hello,", name)
When this runs:
Enter your name: OnePercentDev
Hello, OnePercentDev
The text inside input() is called a prompt — it tells the user what to type.
Everything that comes from input() is a string (text), even if the user types a number.
age = input("Enter your age: ")
print(type(age))
Output:
<class 'str'>
Even if you type 25, Python treats it as the text "25", not the number 25.
To work with numbers from input, convert using int() or float():
age = int(input("Enter your age: "))
print(type(age))
Output:
<class 'int'>
Now age is an actual number and you can do math with it.
Honest answer: In web apps and APIs — no.
In real applications, data comes from different sources:
| Source | Example |
|---|---|
| HTTP request | request.json["name"] in Flask/FastAPI |
| URL parameter | /users?id=42 |
| Database | Query from PostgreSQL, MongoDB |
| Environment variable | os.environ.get("API_KEY") |
| Config file | .env, settings.py |
| Command-line argument | sys.argv[1] |
None of these use input().
Because input() teaches you the concept of receiving external data. The concept is the same everywhere — only the source changes:
# Terminal input
name = input("Enter name: ")
# Web API input
name = request.json["name"]
# Command-line input
import sys
name = sys.argv[1]
# Environment variable input
import os
name = os.environ.get("APP_NAME")
Same idea: data comes in from outside your program. What you learn with input() applies to all of these.
| Use Case | Why input() Works Here |
|---|---|
| CLI tools and scripts | Admin tools that ask "Are you sure? (y/n)" |
| Quick prototypes | Fastest way to test an idea |
| Competitive programming | LeetCode, HackerRank feed data via input() |
| Learning | Building fundamentals before frameworks |
Command-line arguments — data comes with the command, no pausing:
import sys
# Run as: python greet.py OnePercentDev
name = sys.argv[1]
print(f"Hello, {name}")
Environment variables — how real apps load secrets:
import os
api_key = os.environ.get("API_KEY")
print("Key loaded" if api_key else "Warning: no API key")
name = input("What is your name? ")
print("Welcome to OnePercentDev,", name)
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum:", a + b)
print("Difference:", a - b)
print("Product:", a * b)
This program takes two numbers, performs basic math, and shows the results.
Python provides a clean way to embed values inside strings using f-strings (formatted string literals).
name = "OnePercentDev"
age = 28
print(f"My name is {name} and I am {age} years old")
Output:
My name is OnePercentDev and I am 28 years old
The f before the quotes tells Python to look for {} placeholders and replace them with actual values.
f-strings are the modern, preferred way to format output in Python. You will use them constantly.
print(f"{1400000000:,}")
# Output: 1,400,000,000
print(f"{0.9534:.1%}")
# Output: 95.3%
print(f"{0.85:.0%}")
# Output: 85%
print(f"{'Python':*^20}")
# Output: *******Python*******
| Format | What It Does | Example Output |
|---|---|---|
:, | Add commas to numbers | 1,000,000 |
:.1% | Percentage with 1 decimal | 95.3% |
:.0% | Percentage, no decimal | 85% |
:*^20 | Center, fill with * | *******Python******* |
:<20 | Left-align in 20 chars | Python |
:>20 | Right-align in 20 chars | Python |
Every program — from a simple calculator to a complex AI system — follows the same core model:
Input → Process → Output
| Step | What Happens | Example |
|---|---|---|
| Input | Data comes in | User types a number |
| Process | Program does something with the data | Calculate the sum |
| Output | Result goes out | Print the answer |
This model applies everywhere:
Every system you will ever build follows this pattern.
There are two ways to run Python code:
python in terminalmain.py)python main.pyWhen to use which:
| Use Case | REPL or Script? |
|---|---|
| Testing a quick calculation | REPL |
| Checking how a function works | REPL |
| Building an actual program | Script |
| Working on a project | Script |
| Saving your work | Script |
In professional work, scripts are the standard. The REPL is a tool for exploration.
Comments are lines that Python ignores. They are notes for humans reading the code.
# This calculates the user's age
birth_year = int(input("Enter your birth year: "))
current_year = 2026
age = current_year - birth_year
print(f"You are {age} years old")
The # symbol marks a comment. Everything after # on that line is ignored by Python.
Use comments to explain why something is done, not what is done. The code itself should show what is happening. Comments should explain the reasoning behind decisions.
# Emoji — Python 3 supports Unicode natively
print("Python is fun! 🐍🔥")
print("Status: ✅ Complete")
# Walrus operator (Python 3.8+) — assign and print in one line
print(length := len("OnePercentDev"))
# Output: 13
print(f"The name has {length} characters")
# Output: The name has 13 characters
| What You Learned | Where It Shows Up |
|---|---|
print() basics | Daily debugging in development |
sep, end, file, flush | CLI tools, logging, formatted output |
repr() | Debugging invisible characters in data |
print() debugging | Every developer's first instinct when something breaks |
input() concept | Receiving data from any source — HTTP, CLI, env vars |
| f-strings | Log messages, API responses, reports, dashboards |
| Input → Process → Output | Architecture of every backend, pipeline, and AI system |
Build a program in a file called about_me.py that:
Hello [name], you are [age] years old. Welcome to your 1% developer journey!
Build a program in a file called converter.py that:
F = C * 9/5 + 32K = C + 273.15=============================
Temperature Converter
=============================
Celsius: 37.0
Fahrenheit: 98.6
Kelvin: 310.15
=============================
Use float() for conversion, f-strings with :.1f for formatting, and "=" * 29 for the separator.
Save both in your src/ folder and run with python src/about_me.py and python src/converter.py.
Next: Part 6 — How Python actually runs your code. What happens between typing
python main.pyand seeing the output.
Variables Deep Dive: Names, Objects & References Explained | Python in Kannada | Part-8
Part 8
Variables Deep Dive: Names, Objects & References Explained | Python in Kannada | Part-8
Part 8