This repository contains a comprehensive set of Python Object-Oriented Programming (OOP) practice problems. Each problem demonstrates different aspects of OOP concepts in Python.
- Using self
- Using cls
- Public Variables and Methods
- Class Variables and Class Methods
- Static Variables and Static Methods
- Constructors and Destructors
- Access Modifiers
- The super() Function
- Abstract Classes and Methods
- Instance Methods
- Class Methods
- Static Methods
- Composition
- Aggregation
- Method Resolution Order (MRO)
- Function Decorators
- Class Decorators
- Property Decorators
- callable() and call()
- Custom Exceptions
- Custom Iterable Class
Demonstrates the use of self keyword in class methods.
- File:
01_student_self.py - Class:
Student - Features: Constructor with self, instance methods
Shows how to use cls keyword and class methods.
- File:
02_counter_cls.py - Class:
Counter - Features: Class variables, class methods
Illustrates public variables and methods in a class.
- File:
03_car_public.py - Class:
Car - Features: Public attributes, public methods
Demonstrates class variables and class methods.
- File:
04_bank_class_variables.py - Class:
Bank - Features: Class variables, class methods
Shows the use of static methods.
- File:
05_math_utils_static.py - Class:
MathUtils - Features: Static methods
Illustrates constructor and destructor usage.
- File:
06_logger_constructor_destructor.py - Class:
Logger - Features:
__init__,__del__
Demonstrates public, protected, and private access modifiers.
- File:
07_employee_access_modifiers.py - Class:
Employee - Features: Public, protected, and private attributes
Shows how to use the super() function.
- File:
08_person_teacher_super.py - Classes:
Person,Teacher - Features: Inheritance, super()
Illustrates abstract classes and methods.
- File:
09_shape_abstract.py - Classes:
Shape,Rectangle - Features: Abstract classes, abstract methods
Demonstrates instance methods.
- File:
10_dog_instance_methods.py - Class:
Dog - Features: Instance methods
Shows the use of class methods.
- File:
11_book_class_methods.py - Class:
Book - Features: Class methods
Illustrates static methods.
- File:
12_temperature_converter_static.py - Class:
TemperatureConverter - Features: Static methods
Demonstrates composition in OOP.
- File:
13_engine_car_composition.py - Classes:
Engine,Car - Features: Composition
Shows aggregation in OOP.
- File:
14_department_employee_aggregation.py - Classes:
Employee,Department - Features: Aggregation
Illustrates MRO and diamond inheritance.
- File:
15_mro_diamond_inheritance.py - Classes:
A,B,C,D - Features: Multiple inheritance, MRO
Demonstrates function decorators.
- File:
16_function_decorator.py - Features: Function decorators
Shows class decorators.
- File:
17_class_decorator.py - Features: Class decorators
Illustrates property decorators.
- File:
18_product_property_decorators.py - Class:
Product - Features: @property, @setter, @deleter
Demonstrates callable objects.
- File:
19_multiplier_callable.py - Class:
Multiplier - Features:
__call__, callable()
Shows how to create custom exceptions.
- File:
20_custom_exception.py - Class:
InvalidAgeError - Features: Custom exceptions
Illustrates how to make a class iterable.
- File:
21_countdown_iterable.py - Class:
Countdown - Features:
__iter__,__next__
- Clone the repository:
git clone https://github.com/muhammadwaheedairi/python-oop-practice.git- Navigate to the project directory:
cd python-oop-practice- Run any example file:
python 01_student_self.py- Python 3.x
- 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