Python
A general-purpose programming language that reads almost like plain English. This topic covers the language itself: from running your first line to classes and the standard library.
17 pages 120 glossary terms PCEP
How to use this topic
The pages below form a learning path: each one builds on the ones before it, so reading them in order works well if you are new to Python. They also stand on their own as reference pages — every page starts with a short TL;DR.
All examples use Python 3.12 or later and are complete: copy one into a file, run it, and you get the output shown below it. Pages marked PCEP cover material from the PCEP™ – Certified Entry-Level Python Programmer exam. Testing Python code with pytest is covered in Unit Testing with pytest in Testing & QA.
Learning path
- 01What Is Python?What Python is, how the interpreter runs your code, and where the language is used.
- 02Variables and Data TypesHow names refer to objects, and the built-in types for numbers, text, truth values and nothing.
- 03Operators and ExpressionsArithmetic, comparison, logical and bitwise operators, and the order in which Python evaluates them.
- 04StringsCreating, indexing, slicing and formatting text, and the string methods you will use every day.
- 05Input and OutputReading from the keyboard with input(), writing with print(), and turning text into numbers.
- 06Control FlowMaking decisions with if, elif and else, conditional expressions, and structural pattern matching with match.
- 07LoopsRepeating work with for and while, counting with range(), and steering a loop with break, continue and else.
- 08Lists and TuplesOrdered sequences: the mutable list and the immutable tuple, with indexing, slicing, methods and unpacking.
- 09Dictionaries and SetsLooking up values by key with dictionaries, and keeping unique items with sets.
- 10FunctionsDefining reusable blocks of code: parameters and arguments, return values, defaults, keywords and scope.
- 11ComprehensionsBuilding lists, dictionaries and sets in one readable expression, and when a plain loop is clearer.
- 12Error HandlingWhat exceptions are, how to catch them with try, except, else and finally, and how to raise your own.
- 13Files and PathsReading and writing text files safely with open() and with, working with paths in pathlib, and handling CSV and JSON.
- 14Modules, Packages, pip and Virtual EnvironmentsSplitting code into modules and packages, importing it, and installing third-party packages in an isolated environment.
- 15Object-Oriented Programming BasicsClasses and objects, attributes and methods, __init__, and reusing behavior through inheritance.
- 16Useful Standard LibraryA tour of modules that ship with Python: os, sys, datetime, random, collections and json.
- 17Code Style and Good HabitsWriting code others can read: PEP 8, naming, comments and docstrings, and the basics of type hints.
Python glossary
Short definitions of the terms used in this topic. The full glossary covers every topic.