Module 1 · Getting started

What Python is and how it runs

Foundations 14 min read Your first program, and what happens when you run it

Python is a programming language: a precise way of writing instructions that a computer can carry out. You write those instructions as plain text, and a program called the Python interpreter reads them and does what they say, one statement at a time. Python is popular because the text is short and readable, it comes with a large toolbox, and the same language covers web servers, data analysis, automation and AI.

👩‍🍳

A recipe and a chef

Your program is a recipe. The interpreter is a chef who reads it from the top, one step at a time, and actually cooks. If step 7 says "add the saffron" and there is no saffron, the chef stops at step 7 and tells you exactly which line was the problem. Steps 1–6 have already happened. Keep this picture: it explains both how Python runs and how its error messages work.

1. Your first program

print shows something on the screen. Text goes in quotes. Everything after # on a line is a comment: a note for humans that Python ignores.

print("Hello, Python!")        # text in quotes is a string
print(2 + 3)                   # Python can calculate
print("2 + 3 =", 2 + 3)        # print accepts several things, separated by commas
Hello, Python! 5 2 + 3 = 5

A slightly bigger program already uses the ideas this course is built on: names, a list, a loop, and a decision.

prices = {"tea": 120.0, "rice": 85.5, "milk": 32.0}     # a dictionary: item → price
cart = ["tea", "milk", "milk"]                          # a list of items

total = 0
for item in cart:                                       # repeat for each item in the cart
    total = total + prices[item]

print(f"Items: {len(cart)}, total: ₹{total:.2f}")
if total > 150:
    print("Free delivery!")
Items: 3, total: ₹184.00 Free delivery!

Notice the indentation. The lines inside the for and the if are pushed right by four spaces. In Python, indentation is not decoration: it is how you tell Python which lines belong together. Lesson 06 covers it properly.

2. What happens when you run a program

shopping.py plain text you wrote 1 · read & compile check the grammar, turn it into bytecode 2 · execute the Python virtual machine runs it, step by step output SyntaxError: found here, before anything runs other errors: the program stops at that line Bytecode is an internal, compact form of your program. You never need to read it (the Advanced Python course does).

Step 1 is why a missing bracket is reported before a single line runs, while a problem like dividing by zero only appears when Python reaches that line. Here is a grammar mistake. The error message points at the problem with a caret (^):

print("this line would run first")
print("missing a closing bracket"
File "example.py", line 2 print("missing a closing bracket" ^ SyntaxError: '(' was never closed

3. Interpreted, compiled, and where Python sits

Compiled ahead of time (C, Rust, Go)Python
How it runstranslated once into machine code, then runcompiled to bytecode on the fly, run by the interpreter
Speed of raw loopsvery fastmuch slower, but heavy work is usually done by libraries written in C (NumPy, pandas)
Typesusually declared and checked before runningchecked while running (dynamic typing); optional type hints for tools
Feedback loopedit → compile → runedit → run; try things instantly in the REPL

"Python" usually means CPython, the standard interpreter from python.org, written in C. Others exist (PyPy, MicroPython for small devices), but everything in this course is standard CPython.

4. Two ways to run Python: the REPL and scripts

The REPL (interactive)

Type python in a terminal and you get a >>> prompt. Each line runs as soon as you press Enter, and the value of an expression is shown automatically. Perfect for experiments.

A script (a .py file)

Save code in hello.py and run python hello.py. It runs top to bottom. Only what you print is shown. This is how real programs are run.

>>> 7 * 6
42
>>> name = "Asha"
>>> name.upper()
'ASHA'
>>> exit()

5. Which Python are you running?

import sys
import platform

print("Python", platform.python_version())
print("implementation:", platform.python_implementation())
print("is it at least 3.12?", sys.version_info >= (3, 12))
Python 3.14.6 implementation: CPython is it at least 3.12? True

There is only one Python today: Python 3. (Python 2 reached end of life in 2020, so ignore any tutorial that writes print "hi" without brackets.) A new 3.x version is released every October, and this course needs 3.12 or newer.

6. Python's personality

A short poem ships inside Python itself. It explains the style you will see in this course:

import this
The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!

"Readability counts" and "There should be one obvious way to do it" explain a lot of Python's design. When two solutions work, prefer the one a colleague understands at first reading.

7. What people build with Python

AreaTypical toolsOn this site
Web back ends and APIsFastAPI, Django, Flaskthe FastAPI course
Data analysis and engineeringpandas, PySpark, SQLthe PySpark, SQL and Databricks courses
AI and machine learningscikit-learn, PyTorch, the OpenAI SDKthe OpenAI SDK and AI Engineering courses
Automation and scriptingthe standard library, requests, CLIsthis course's project
Testing and DevOpspytest, Ansible, cloud SDKslesson 19
Non-technical summary

Python is a language for giving a computer instructions in text that reads almost like English. A program called the interpreter follows the instructions line by line. It is slower than some languages at raw number-crunching, but it is fast to write, easy to read, and has ready-made libraries for almost everything, which is why so many teams use it.

Recap

  • The interpreter reads your code, checks its grammar, compiles it to bytecode, and runs it top to bottom.
  • SyntaxErrors are found before anything runs; other errors stop the program at the failing line.
  • Indentation groups lines into blocks. It is part of the language.
  • The REPL is for experiments; scripts (python file.py) are real programs.

Checkpoint

1 · Line 10 of a script has a missing closing bracket. What happens to lines 1–9?
A SyntaxError is found in the compile step, before the program starts. Errors like dividing by zero only happen when the line runs.
2 · In the REPL, typing 7 * 6 shows 42. In a script, the same line shows nothing. Why?
The REPL is a convenience for exploring. In a program, use print() to show a value.