Skip to content

A hands-on Python repository to master core Object-Oriented Programming (OOP) concepts through real-world practice problems.

muhammadwaheedairi/python-oop-practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python OOP Practice Series

This repository contains a comprehensive set of Python Object-Oriented Programming (OOP) practice problems. Each problem demonstrates different aspects of OOP concepts in Python.

Table of Contents

  1. Using self
  2. Using cls
  3. Public Variables and Methods
  4. Class Variables and Class Methods
  5. Static Variables and Static Methods
  6. Constructors and Destructors
  7. Access Modifiers
  8. The super() Function
  9. Abstract Classes and Methods
  10. Instance Methods
  11. Class Methods
  12. Static Methods
  13. Composition
  14. Aggregation
  15. Method Resolution Order (MRO)
  16. Function Decorators
  17. Class Decorators
  18. Property Decorators
  19. callable() and call()
  20. Custom Exceptions
  21. Custom Iterable Class

Problem Descriptions

1. Using self

Demonstrates the use of self keyword in class methods.

  • File: 01_student_self.py
  • Class: Student
  • Features: Constructor with self, instance methods

2. Using cls

Shows how to use cls keyword and class methods.

  • File: 02_counter_cls.py
  • Class: Counter
  • Features: Class variables, class methods

3. Public Variables and Methods

Illustrates public variables and methods in a class.

  • File: 03_car_public.py
  • Class: Car
  • Features: Public attributes, public methods

4. Class Variables and Class Methods

Demonstrates class variables and class methods.

  • File: 04_bank_class_variables.py
  • Class: Bank
  • Features: Class variables, class methods

5. Static Variables and Static Methods

Shows the use of static methods.

  • File: 05_math_utils_static.py
  • Class: MathUtils
  • Features: Static methods

6. Constructors and Destructors

Illustrates constructor and destructor usage.

  • File: 06_logger_constructor_destructor.py
  • Class: Logger
  • Features: __init__, __del__

7. Access Modifiers

Demonstrates public, protected, and private access modifiers.

  • File: 07_employee_access_modifiers.py
  • Class: Employee
  • Features: Public, protected, and private attributes

8. The super() Function

Shows how to use the super() function.

  • File: 08_person_teacher_super.py
  • Classes: Person, Teacher
  • Features: Inheritance, super()

9. Abstract Classes and Methods

Illustrates abstract classes and methods.

  • File: 09_shape_abstract.py
  • Classes: Shape, Rectangle
  • Features: Abstract classes, abstract methods

10. Instance Methods

Demonstrates instance methods.

  • File: 10_dog_instance_methods.py
  • Class: Dog
  • Features: Instance methods

11. Class Methods

Shows the use of class methods.

  • File: 11_book_class_methods.py
  • Class: Book
  • Features: Class methods

12. Static Methods

Illustrates static methods.

  • File: 12_temperature_converter_static.py
  • Class: TemperatureConverter
  • Features: Static methods

13. Composition

Demonstrates composition in OOP.

  • File: 13_engine_car_composition.py
  • Classes: Engine, Car
  • Features: Composition

14. Aggregation

Shows aggregation in OOP.

  • File: 14_department_employee_aggregation.py
  • Classes: Employee, Department
  • Features: Aggregation

15. Method Resolution Order (MRO)

Illustrates MRO and diamond inheritance.

  • File: 15_mro_diamond_inheritance.py
  • Classes: A, B, C, D
  • Features: Multiple inheritance, MRO

16. Function Decorators

Demonstrates function decorators.

  • File: 16_function_decorator.py
  • Features: Function decorators

17. Class Decorators

Shows class decorators.

  • File: 17_class_decorator.py
  • Features: Class decorators

18. Property Decorators

Illustrates property decorators.

  • File: 18_product_property_decorators.py
  • Class: Product
  • Features: @property, @setter, @deleter

19. callable() and call()

Demonstrates callable objects.

  • File: 19_multiplier_callable.py
  • Class: Multiplier
  • Features: __call__, callable()

20. Custom Exceptions

Shows how to create custom exceptions.

  • File: 20_custom_exception.py
  • Class: InvalidAgeError
  • Features: Custom exceptions

21. Custom Iterable Class

Illustrates how to make a class iterable.

  • File: 21_countdown_iterable.py
  • Class: Countdown
  • Features: __iter__, __next__

Getting Started

  1. Clone the repository:
git clone https://github.com/muhammadwaheedairi/python-oop-practice.git
  1. Navigate to the project directory:
cd python-oop-practice
  1. Run any example file:
python 01_student_self.py

Requirements

  • Python 3.x

Acknowledgments

  • These examples are part of a comprehensive OOP practice series
  • Each example is self-contained and includes detailed comments
  • All examples include practical usage demonstrations

About

A hands-on Python repository to master core Object-Oriented Programming (OOP) concepts through real-world practice problems.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages