Python · Module 01: Getting Started & How Python ThinksTutorial 1 of 30

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.

01 Intuition: Plain-English mental model
02 Visuals: Step-by-step diagrams
03 Practice: Clean examples & tradeoffs

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.

Visual: Why Learning Python Opens 5 Major Engineering Careers
One Language: PythonWeb BackendsDjango, FastAPIAI & MLPyTorch, LLMsData & SQLPandas, SparkAutomationScripts, BotsInterviewsCleanest DSA

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:

  1. Compile to Bytecode (.pyc): When you run python hello.py, Python checks your syntax and translates your code into compact instructions called bytecode (hidden inside a __pycache__ folder).
  2. Execute on the Python Virtual Machine (PVM): The PVM reads that bytecode instruction by instruction and executes it on your computer's CPU.
Visual: How Python Turns Your English-Like Code Into Action (CPython Pipeline)
1. Your Filehello.pyprint("Hi!")2. Bytecode (.pyc)LOAD_NAME printLOAD_CONST "Hi!"(Hidden & automatic)3. Python VM (PVM)Executes Lineby Line on CPU4. Terminal> Hi!Instant resultUnlike C++ (which requires a manual compile step first), Python translates & runs your file in one command.
FeaturePython (CPython)C / C++
How you run itSingle command: python app.pyManual compile (g++ app.cpp) then run (./a.out)
Learning curveVery beginner-friendly (reads like English)Steeper (manual memory pointers, headers, types)
Execution speedFast enough for 95% of apps (C libraries power AI/Data)Fastest raw CPU speed
Best known forAI/ML, Web Backends, Automation, Data, InterviewsGame 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.org or run brew install python in 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:

BASH
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:

PYTHON
>>> 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:

PYTHON
# 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:

BASH
python3 hello.py

Console Output:

TEXT
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:

Tracing Your First Python Script
Interactive Line-by-Line Execution Trace · Step 1 of 4
1→print("Starting program...")
2name = "Aarav"
3print("Welcome,", name)
4print("Done!")
Variables in Memory
No variables created yet
Console Output
> Starting program...
What just happened: Python calls the built-in print() function and displays the text "Starting program..." in the terminal.

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:

PYTHON
# ✓ 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

Q1.What happens if you write Print('Hello') with a capital 'P' in Python?
Q2.What does CPython actually do when you run `python3 app.py`?
Q3.What will this code print?
print("Python", 3, "is fun!")

Keep Exploring: Related Lessons & Tools

All Courses →