OOP bundles data and behavior into objects, making complex programs easier to organize and extend.
Work through the concepts using Python in your editor or Replit. Use the knowledge check below to test yourself.
Open a Python file and implement the core concepts from this lesson. Start small, test each part, then combine.
In OOP, what is an instance?
The class is the blueprint. An instance is a specific object created from that blueprint.
Methods are functions belonging to a class. An instance is a particular object created by calling the class.
__init__ is called when creating an instance, but __init__ itself is the constructor method, not the instance.
What is the purpose of self in a method definition?
self is the instance being operated on. To reference the class use type(self) or the class name directly.
self is just a naming convention - you could name it anything. But it's universally followed. It's not a Python keyword.
super() provides access to the parent class. self refers to the current instance.
What does __init__ do?
__del__ is the destructor. __init__ is called when an object is created to initialize its attributes.
__str__ defines what print(obj) shows. __init__ sets up the object's initial state.
__init__ initializes a new object. Copying is a separate operation.
What does @property decorator do?
@property makes a method callable without parentheses (like an attribute). No speed effect.
@property alone just makes it accessible like an attribute. To make it truly immutable, define only a getter, no setter.
@classmethod makes a method receive the class (cls) instead of the instance. @property makes a method behave like an attribute.
What is encapsulation?
Encapsulation is a design principle: bundle data and the methods that operate on it together, hiding internal details.
Inheritance lets a subclass reuse parent class behavior. Encapsulation is about bundling and hiding internals.
Encapsulation often means making attributes private (prefixed with _) and exposing controlled access through methods/properties.