Phase 1 · FoundationsModule 1~32 min read

Introduction to Programming & Python

What programming really is, how Python runs your code, why Python is everywhere, and writing your very first program — the Pythonic way.

What you'll learn

Welcome to your first step as a Python developer. Before writing much code, this module builds the mental model that makes everything click — what programming is, how Python turns your text into a running program, why Python became one of the most loved languages in the world, and how to write and run your first program.

By the end of this module you'll be able to:

  • Explain what programming is and how a computer runs your instructions
  • Describe how Python runs code — the interpreter, CPython, and bytecode
  • Understand what Python is and the huge range of things it powers
  • Install Python and use the interactive interpreter (the REPL)
  • Write, save, and run your first Python program
  • Recognise the anatomy of a Python program, including why indentation matters
  • Comment your code and appreciate the "Zen of Python"

How to use this lesson

Read once for the big picture, then come back and run each example yourself — every one has a Run button. Typing code and watching it work is how it truly sticks.

What is programming?

A computer is astonishingly fast but completely literal — it does exactly what it's told. Programming is the craft of writing precise, unambiguous instructions that a computer can follow to solve a problem or perform a task.

The instructions you write in a language like Python are called source code. But a computer's processor only understands machine code — raw numeric instructions. Something has to translate your readable Python into something the machine can run. How that translation works is the key idea of this module.

Key idea

A program is just a list of instructions. The real skill of programming is breaking a problem into steps so simple and precise that a machine can follow them without guessing.

Compiled vs interpreted languages

There are two classic ways to turn source code into something that runs. Compiled languages (like C or C++) use a compiler to translate the entire program into machine code ahead of time, producing a file that runs directly on the processor — very fast, but tied to one platform.

Interpreted languages run your code through another program — an interpreter — that reads and executes it as the program runs. This is wonderfully flexible and portable, and it's the model Python follows. Python is often called interpreted, though under the hood it uses a clever hybrid step you'll see next.

Note

The trade-off: interpreted languages like Python are a little slower than fully compiled ones, but far more flexible, portable, and quick to write. For the vast majority of work, that's a trade worth making — and libraries like NumPy give you compiled-level speed where you need it.

What is Python?

Python is a high-level, general-purpose programming language created by Guido van Rossum and first released in 1991. It was designed around one core idea: code should be easy to read and write. Its clean, English-like syntax is a huge part of why it's the most popular language for beginners and a favourite of professionals.

Three decades on, Python is beloved because it is:

  • Readable — the syntax reads almost like plain English
  • Batteries included — a huge standard library and a vast ecosystem of packages
  • Versatile — used across an enormous range of fields
  • Beginner-friendly, yet powerful — easy to start, deep enough for experts
Where Python is used

Data Science & AI

The #1 language for machine learning, analytics, and research.

Web Development

Powers backends with Django, Flask, and FastAPI.

Automation & Scripting

Automate boring tasks, files, and workflows in a few lines.

Everything else

DevOps, scientific computing, finance, game scripting, and more.

One language, an enormous range of applications.

Python 2 vs Python 3

You may see references to Python 2 — it's the old version, officially retired in 2020. Always use Python 3 (3.12 or newer). Every example in this course is Python 3.

How Python runs your code

The standard Python you'll install is called CPython (Python's reference implementation, written in C). When you run a program, CPython quietly does two things: it compiles your source into an intermediate format called bytecode, then a component called the Python Virtual Machine (PVM) executes that bytecode:

How Python runs your code
hello.py
Source code
You write this
CPython
Compiler
Compiles it
bytecode
.pyc
Portable instructions
PVM
Python VM
Runs the bytecode
Any OS
Win · macOS · Linux
Same code, anywhere
Source → bytecode → the Python Virtual Machine → any operating system.

You never see the bytecode step — it happens automatically (sometimes cached in .pyc files to speed up future runs). Because your program targets the PVM rather than a specific operating system, the same Python code runs unchanged on Windows, macOS, and Linux.

Key idea

This is why Python feels so immediate: there's no separate "compile" button to press. You write code and run it, and CPython handles the compile-to-bytecode step behind the scenes.

Installing Python & the REPL

Getting set up takes just a few steps:

  1. Download Python 3 from python.org (on Windows, tick "Add Python to PATH" in the installer). macOS and Linux often have Python already, but install a current version to be sure.
  2. Install an editor — VS Code or PyCharm are excellent and free.
  3. Verify it works by checking the version in a terminal:
Terminal
python --version
If you see a 3.x version number, Python is installed.

Python also gives you an interactive playground called the REPL (Read-Eval-Print Loop). Type python in a terminal and you can run code line by line, seeing results instantly — perfect for experimenting. The >>> is Python's prompt:

Python REPL
>>> 2 + 3
5
>>> name = "Sara"
>>> print(f"Hi, {name}!")
Hi, Sara!
>>> len("Python")
6

Tip

The REPL is your best friend while learning. Whenever you wonder "what does this do?", open it and try. There's no faster way to build intuition.

Your first program: Hello, World!

By tradition, the first program in any language prints "Hello, World!". In Python, that's a single, readable line. Press Run to see it work:

hello.py
print("Hello, World!")
Your very first Python program — really, that's the whole thing.

Compare that to the same program in a language like Java, and Python's design philosophy jumps out immediately:

Simplicity by design

Java — "Hello, World!"

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Python — "Hello, World!"

print("Hello, World!")

Same result, one line. No class, no main, no boilerplate — that's Python's philosophy of readability and simplicity.

To run this yourself, save it in a file called hello.py, then in a terminal type:

Terminal
python hello.py

Now let's make it interactive. This next program asks for your name and greets you, using input() to read what you type and an f-string to slot the name into the message:

greet.py
name = input("What's your name? ")
print(f"Hello, {name}! Welcome to Python.")
Press Run to see a sample interaction.

Anatomy of a Python program

Even that tiny print line has parts worth naming. Let's dissect it:

print, dissected
print1(2"Hello, World!"3)
1

A function call

print is a built-in function that displays text on the screen.

2

Parentheses

The ( ) call the function, passing it whatever is inside as an argument.

3

A string

Text wrapped in quotes — the value we want to print.

Notice what's not there: no class, no main function, no semicolons, no curly braces. Python strips programs down to their essence. But it has one famous rule that surprises newcomers — indentation is part of the syntax. Where other languages use braces to group code, Python uses indentation (spaces at the start of a line). Lines indented the same amount belong to the same block:

indentation.py
if 5 > 2:
    print("Five is greater than two")   # indented -> inside the if
    print("Both of these lines run")

print("This line always runs")          # not indented -> outside

Indentation is not optional

In Python, indentation defines which lines belong together. Getting it wrong is a real error (IndentationError), not just a style issue. Use a consistent 4 spaces per level — the standard, and what every editor inserts when you press Tab.

Comments & docstrings

Comments are notes for humans that Python ignores. Anything after a # on a line is a comment. Python also has docstrings — triple-quoted strings placed at the top of a function, class, or module to document what it does:

comments.py
# This is a single-line comment — Python ignores it.

x = 5  # comments can also sit at the end of a line

def greet(name):
    """Return a friendly greeting.

    Text like this (a docstring) documents what a function does.
    """
    return f"Hello, {name}"

print(greet("World"))

Tip

Great comments explain why, not what. If the code already shows what's happening, don't restate it — capture the reasoning the code can't. And write a docstring for every function you'll want to remember or share.

The Zen of Python

Python has a famous, slightly playful guiding philosophy. Type import this into the REPL and it prints The Zen of Python — 19 aphorisms that capture how Pythonic code should feel:

Python REPL
import this
A taste of the Zen

The Zen of Python — a few lines

  • Beautiful is better than ugly.
  • Simple is better than complex.
  • Readability counts.
  • There should be one — and preferably only one — obvious way to do it.
  • Now is better than never.

Note

These aren't just cute sayings — they're the values the whole language is built on. As you learn, keep asking "is this the simple, readable, obvious way?" That instinct is what makes code Pythonic.

Recap & quick check

Key takeaways

  • Programming is writing precise, unambiguous instructions a computer can execute.
  • Python is compiled to bytecode by CPython, then run by the Python Virtual Machine — the same code runs anywhere.
  • Python is high-level, readable, and versatile — huge in data science, web, automation, and more. Always use Python 3.
  • print() displays text; input() reads it; f-strings slot values into text.
  • Python uses indentation (4 spaces) instead of braces to group code — it's part of the syntax, not just style.

Quick check

1. How does the standard Python (CPython) run your program?

2. What does Python use to group blocks of code?

3. Which function displays text on the screen?

4. Which version of Python should you use today?

5. What is the REPL?

Brilliant — you understand how Python works and you've run your first program. Next up: Module 2 — Variables, Data Types & Operators, where you'll start storing and manipulating real data.