Glossary

Object

An object in Python is any entity that has an identity (a unique integer returned by id()), a type (returned by type()), and a value. Everything in Python is an object: integers, strings, functions, modules, classes, and even None. This uniform object model is one of Python's defining characteristics and enables its dynamic nature.

Each object's type determines what operations it supports and what attributes it has. The type is itself an object (an instance of type), and types can be inspected at runtime with isinstance() and issubclass(). Python's dynamic typing means an object's type is fixed at creation, but a variable name can be rebound to objects of different types freely.

Objects are created by calling a class (its constructor), by using literal syntax (e.g., [1, 2, 3] creates a list object), or by operations that return new objects (e.g., a + b). Objects are destroyed by the garbage collector when no references to them remain. CPython uses reference counting as its primary garbage collection mechanism, supplemented by a cyclic garbage collector for detecting reference cycles. The distinction between mutable and immutable objects is central to understanding Python's behaviour.

Related terms: Class, Instance, Mutable, Immutable

Discussed in:

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