Complete Solutions
What is the purpose of the `self` parameter in Python class methods?
✔✔`self` refers to the instance of the class and allows access to its attributes and methods.
How do you define a class in Python?
✔✔You define a class using the `class` keyword followed by the class name and a colon.
What is the difference between a class method and an instance method in Python?
✔✔A class method operates on the class itself, while an instance method operates on an instance
of the class.
What does the `__str__()` method do in a Python class?
✔✔The `__str__()` method defines how an object is represented as a string when it is printed or
converted to a string.
How do you create an object from a class in Python?
1
, ✔✔You create an object by calling the class name followed by parentheses: `object =
ClassName()`.
What does inheritance allow in Python?
✔✔Inheritance allows a class to inherit attributes and methods from another class, enabling code
reuse and extension.
How do you access the parent class's method in a subclass?
✔✔You use the `super()` function to access a method from the parent class.
What is method overriding in Python?
✔✔Method overriding is when a subclass provides a new definition for a method that is already
defined in its parent class.
What is the purpose of the `__init__()` method in Python classes?
✔✔The `__init__()` method is the constructor method in Python, used to initialize an object's
attributes when it is created.
How do you prevent a method from being overridden in Python?
2