Classes_and_Objects
Classes_and_Objects
• class Car:
• def __init__(self, brand, model):
• self.brand = brand
• self.model = model
• def display_info(self):
• return f'{self.brand} {self.model}'
Creating and Using Objects
• - Objects are instances of a class.
• - Each object has its own attributes and can
execute class methods.
• - Example:
• class Vehicle:
• total_vehicles = 0
Constructors and Destructors
• - **Constructor (`__init__`)**: Initializes an
object.
• - **Destructor (`__del__`)**: Cleans up
resources when an object is deleted.
• - Example:
• class Example:
• def __init__(self, name):
• self.name = name
Conclusion
• - **Classes** define the structure and
behavior of objects.
• - **Objects** are instances of a class that
store data and perform actions.
• - Understanding classes and objects is
essential for Object-Oriented Programming.