FlashKeepers

Python · Python

Python: Object-Oriented Programming

Python classes, inheritance, and object-oriented concepts explained with a short example each.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone
What is a class in Python?
A blueprint or template for creating objects with shared attributes and methods
How does an object relate to a class?
An object is a concrete instance of a class containing actual data
What Python keyword is used to define a class?
class
What is the __init__ method in a class?
The constructor that is automatically called when a new instance is created
What does the self parameter represent in a method?
A reference to the current instance of the class
What is an instance attribute?
An attribute that belongs to a single object and can differ across instances
What is a class attribute?
An attribute defined in the class body that is shared by all instances
What is inheritance in object-oriented programming?
A mechanism where a child class acquires the attributes and methods of a parent class
How do you create a child class that inherits from a parent?
class ChildClass(ParentClass):
What is method overriding?
Redefining a method from the parent class in the child class with different behavior
What does super() do?
Calls a method in the parent class from within the child class
What is encapsulation in OOP?
Bundling data and methods together and hiding internal implementation details
What does a single underscore prefix on an attribute mean?
By convention, it signals the attribute is intended to be private or internal
What does a double underscore prefix on an attribute do?
It triggers name mangling to make the attribute harder to access from outside the class
What does the @property decorator allow?
Defining a method that can be accessed and used like an attribute with dot notation

25 more cards in the app