- Using self: Create
Studentclass, useselfto setname&marks, adddisplay()to print details. - Using cls: Create
Counterclass, track object count with class variable & method usingcls. - Public Variables/Methods: Create
Carclass with publicbrand&start(), access both externally. - Class Variables/Methods: Create
Bankclass withbank_name, addchange_bank_name(cls, name)to update it for all instances. - Static Methods: Create
MathUtilsclass with static methodadd(a, b)to return sum, no class/instance variables. - Constructors/Destructors: Create
Loggerclass, print messages on object creation & destruction. - Access Modifiers: Create
Employeeclass with publicname, protected_salary, private__ssn, test access. - super(): Create
Personclass to set name, inheritTeacher, addsubject, usesuper()to call parent constructor. - Abstract Classes: Use
abcto createShapewith abstractarea(), inheritRectangleto implementarea(). - Instance Methods: Create
Dogclass withname&breed, addbark()to print message with name. - Class Methods: Create
Bookclass withtotal_books, addincrement_book_count()to increase count. - Static Methods: Create
TemperatureConverterwith staticcelsius_to_fahrenheit(c)to return Fahrenheit. - Composition: Create
Engine&Car, passEnginetoCarduring init, accessEnginemethod viaCar. - Aggregation: Create
Department&Employee, use aggregation to store independentEmployeeinDepartment. - MRO & Diamond Inheritance: Create
A,B,C,Dclasses, overrideshow()inB&C,Dinherits both, test MRO. - Function Decorators: Write
log_function_calldecorator to print message beforesay_hello()executes. - Class Decorators: Create
add_greetingdecorator to addgreet()method toPersonclass. - Property Decorators: Create
Productwith private_price, use@property,@setter,@deleterto manage it. - callable() & call(): Create
Multiplier, set factor, use__call__()to multiply input, test withcallable(). - Custom Exception: Create
InvalidAgeError, raise incheck_age(age)if age < 18, handle with try-except. - Custom Iterable: Create
Countdown, take start number, use__iter__()&__next__()to count down to 0 in for-loop.
Enter the assignment folder,
cd 01_Using_SelfRun the script with:
python app.pyRequires only a standard Python 3+ installation, no external libraries needed.
These exercises aim to teach:
Object initialization and manipulation
Access and visibility rules
Inheritance and method behavior
Abstract design patterns
Decorator applications
Custom object capabilities
Dive into Python OOP and enjoy the journey! 🌟