Introduction to Python

Python is a general-purpose programming language known for code that reads almost like plain English. It's used for web back ends, data analysis, machine learning, automation scripts, scientific research and teaching — and it's one of the most popular languages in the world.

A first look

Here's a complete Python program. Press Run to execute it right here in your browser:

Try it yourself
Console output

The first run downloads a Python interpreter into your browser (a few seconds); after that, examples run instantly. You can edit the code and run it again as often as you like.

What makes Python different

  • Readable syntax. No semicolons or curly braces. Indentation shows the structure of the code, so every Python program looks tidy.
  • Batteries included. The standard library covers files, dates, JSON, maths, regular expressions, networking, testing and much more, with nothing extra to install.
  • A huge ecosystem. Over half a million third-party packages are available — pandas, NumPy, Django, Flask, FastAPI, PyTorch and more.
  • Interpreted and dynamic. You run code directly, without a separate compile step, and variables don't need declared types.

The same task in two languages

Compare reading the lines of a file and printing the long ones. In Java:

TXT LongLines.java
import java.nio.file.*;
import java.util.List;

public class LongLines {
    public static void main(String[] args) throws Exception {
        List<String> lines = Files.readAllLines(Path.of("notes.txt"));
        for (String line : lines) {
            if (line.length() > 40) {
                System.out.println(line);
            }
        }
    }
}

In Python:

PY long_lines.py
with open("notes.txt") as file:
    for line in file:
        if len(line) > 40:
            print(line, end="")

Less ceremony means you spend more time on the problem and less on the language.

Where Python is used

AreaTypical tools
Data analysis and visualisationpandas, NumPy, Matplotlib, Jupyter notebooks
Machine learning and AIscikit-learn, PyTorch, TensorFlow, Hugging Face
Web back ends and APIsDjango, Flask, FastAPI
Automation and scriptingStandard library, Requests, Selenium, Playwright
Science, engineering, financeSciPy, SymPy, Astropy, QuantLib
DevOps and toolingAnsible, cloud SDKs, build scripts

CodeAtlas has follow-on courses for several of these — NumPy, pandas, Django and Data Science.

Python versions

This course uses modern Python 3 (3.12 and later), which is what you should install. Python 2 reached end of life in 2020; you may still see its print "hello" syntax (without parentheses) in very old tutorials, but it won't run in Python 3. New Python versions are released every October — lesson 55 summarises recent additions.

How this course works

  • Examples show their real output underneath. Every example has been run to check that output is exactly right.
  • Try it yourself editors run Python in your browser — press Run or Ctrl+Enter.
  • When you finish, practise with the exercises and the quiz.
Tip: don't just read the examples — change them. Break them on purpose and read the error messages. Python's errors are unusually helpful, and learning to read them is one of the most valuable skills you can build.