1.1 What is Python, How It Works & Your First Program
Start from absolute zero: learn what Python is, how the CPython interpreter executes your code behind the scenes, how to install Python, and write your first working program.
1. What Is Python? (Plain-English Analogy)
Imagine you want to give instructions to a chef who only understands binary switches (0s and 1s). Writing raw machine code (10110000 01100001) is exhausting and error-prone.
Python is like writing a recipe in clean, everyday English — and having a super-fast translator (the Python Interpreter) read your recipe line by line and tell the computer's CPU exactly what to do.
Created by Guido van Rossum in 1991, Python was designed with one core philosophy: code is read far more often than it is written. That is why Python skips noisy curly braces {} and semicolons ;, letting you focus on logic instead of punctuation.
2. How Does Python Actually Run Your Code?
Many beginners hear "Python is an interpreted language" and imagine Python reads plain text directly on the CPU. Under the hood, the standard Python engine (CPython) actually does a quick, automatic 2-step relay:
- Compile to Bytecode (
.pyc): When you runpython hello.py, Python checks your syntax and translates your code into compact instructions called bytecode (hidden inside a__pycache__folder). - Execute on the Python Virtual Machine (PVM): The PVM reads that bytecode instruction by instruction and executes it on your computer's CPU.
| Feature | Python (CPython) | C / C++ |
|---|---|---|
| How you run it | Single command: python app.py | Manual compile (g++ app.cpp) then run (./a.out) |
| Learning curve | Very beginner-friendly (reads like English) | Steeper (manual memory pointers, headers, types) |
| Execution speed | Fast enough for 95% of apps (C libraries power AI/Data) | Fastest raw CPU speed |
| Best known for | AI/ML, Web Backends, Automation, Data, Interviews | Game engines, OS kernels, High-frequency trading |
3. Installing Python & Checking Your Setup
Before writing code, make sure you have Python 3.10 or newer installed:
- Windows: Download the official installer from
python.org/downloads. Crucial: Check the box "Add python.exe to PATH" at the bottom of the first screen before clicking Install Now. - macOS: Install via
python.orgor runbrew install pythonin Terminal. - Linux (Ubuntu/Debian): Usually pre-installed; run
sudo apt update && sudo apt install python3.
Open your terminal (Command Prompt / PowerShell on Windows, Terminal on Mac/Linux) and verify:
python3 --version
# Expected output (example):
# Python 3.12.4
(On Windows, the command is usually python --version or py --version.)
4. Two Ways to Run Python: REPL vs. .py Script
Way 1: Interactive Mode (The REPL)
Type python3 in your terminal and press Enter. You will see >>>. This is the REPL (Read–Evaluate–Print–Loop) — like a super-powered calculator where every line runs immediately:
>>> 10 + 25
35
>>> "Hello " * 3
'Hello Hello Hello '
>>> exit()
Way 2: Script Mode (Real Programs)
For real programs, create a file ending in .py (for example hello.py) in VS Code or any text editor:
# hello.py — Your very first Python script!
print("Hello, BigOSlate!")
print("2 + 3 =", 2 + 3)
print("Welcome to Python A-Z!")
Run it from your terminal:
python3 hello.py
Console Output:
Hello, BigOSlate!
2 + 3 = 5
Welcome to Python A-Z!
5. Interactive Trace: Watch Python Execute Top-to-Bottom
Python executes statements strictly from top to bottom, one line at a time. Click Next below to watch how Python runs a 4-line script:
6. Two Golden Rules Every Fresher Must Know on Day 1
Rule 1: Python Is Case-Sensitive
print("Hi") works, while Print("Hi") or PRINT("Hi") crashes with a NameError. Always use exact lowercase for built-in keywords and functions.
Rule 2: Indentation (Leading Spaces) Matters!
In C++ or Java, indentation is optional because curly braces { } define code blocks. In Python, indentation IS the structure. Never add random spaces at the start of a top-level line:
# ✓ Valid
print("Line 1")
print("Line 2")
# ✗ Crashes with IndentationError: unexpected indent
print("Line 1")
print("Line 2")
Pro Tip: Standard Python style (PEP 8) uses 4 spaces per indentation level (never mix Tabs and Spaces).
Quick Quiz: Module 1.1 — Getting Started with Python
print("Python", 3, "is fun!")Keep Exploring: Related Lessons & Tools
All Courses →Paste any Python, JS, Java, or C++ snippet to estimate Time & Space complexity, or enter input size N to see which algorithms pass in 1s.
Test regular expressions live with color-coded match highlights, capture group inspection, plain-English token breakdown, find-and-replace, and Python/JS snippets.