Glossary

Class

A class in Python is a template for creating objects. Defined with the class keyword, a class encapsulates data (attributes) and behaviour (methods) into a single unit. When you call a class — obj = MyClass() — Python creates a new instance of that class, calls the __init__ method to initialise it, and returns the instance. Classes are the foundation of Python's object-oriented programming.

Every value in Python is an object, and every object has a class (accessible via type(obj) or obj.__class__). Even classes themselves are objects — they are instances of type, Python's default metaclass. This "everything is an object" philosophy means that classes can be passed as arguments, stored in collections, and created dynamically at runtime.

Python classes support inheritance (single and multiple), properties (managed attributes), dunder methods (special methods like __init__, __str__, __eq__, __len__ that integrate with built-in operations), and class methods and static methods via decorators. The dataclasses module (Python 3.7+) provides a decorator that auto-generates __init__, __repr__, __eq__, and other methods from type-annotated class attributes, reducing boilerplate for data-holding classes.

Related terms: Object, Instance, Self, Inheritance, Dunder Method

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.