Skip to content

Latest commit

 

History

History

05-oop

Overview

OOP helps in organizing code by grouping related data and functionality into classes and objects.

Files

1. classes_objects.py

Purpose: Shows the basics of creating classes and objects.

  • Class: A blueprint for creating objects (e.g., Car).
  • Object: An instance of a class (e.g., my_car).
  • Attributes: Characteristics of an object (e.g., make, model).
  • Methods: Functions defined inside a class (e.g., display_info).

2. inheritance.py

Purpose: Demonstrates how to use inheritance to extend classes.

  • Inheritance: A way to create a new class from an existing class (e.g., ElectricCar inherits from Vehicle).
  • Subclass: The new class that inherits (e.g., ElectricCar).
  • Superclass: The class being inherited from (e.g., Vehicle).

3. polymorphism_encapsulation.py

Purpose: Covers polymorphism and encapsulation.

  • Polymorphism: Allows different classes to be treated through a common interface (e.g., Shape class with area method).
  • Encapsulation: Hides internal data and only exposes necessary parts (e.g., using private attributes in Rectangle).

4. special_methods.py

Purpose: Shows how to use special (magic) methods in Python.

  • Special Methods: Methods with double underscores (e.g., __add__, __eq__).
  • Usage: Define how objects behave with built-in operations (e.g., addition, comparison).