Python Advanced
Object-Oriented Programming
Classes and Objects
- Class definition and instantiation
- Instance variables vs class variables
- Methods: instance methods, class methods, static methods
- Constructor (
__init__) and destructor (__del__) - Property decorators
Inheritance
- Single inheritance
- Multiple inheritance and MRO (Method Resolution Order)
- Method overriding
- super() function
- Abstract base classes (ABC)
Special Methods
__str__and__repr____len__,__getitem__,__setitem____eq__,__lt__,__hash____call__for callable objects__enter__and__exit__for context managers
Encapsulation
- Private attributes (name mangling)
- Protected attributes
- Property decorators (@property, @setter, @deleter)
Decorators and Generators
Decorators
- Function decorators
- Class decorators
- Decorator with arguments
- Built-in decorators (@staticmethod, @classmethod, @property)
- functools.wraps for preserving metadata
Generators
- Generator functions (yield keyword)
- Generator expressions
- Generator vs list comprehensions
- Sending values to generators
- Generator pipelines
Context Managers
Context Manager Protocol
__enter__and__exit__methods- Using
withstatement - Exception handling in context managers
- contextlib module
- @contextmanager decorator
Use Cases
- File handling
- Database connections
- Resource management
- Lock management
Type Hints
Type Annotations
- Basic type hints (int, str, list, dict)
- Optional and Union types
- Generic types (List, Dict, Tuple)
- Type aliases
- Callable types
- TypedDict for dictionaries
Type Checking
- mypy for static type checking
- Type hints in function signatures
- Type hints for class attributes
- Forward references
Practice Questions
Test your understanding with the questions in the interactive quiz below (when available).
Resources
- Python OOP Tutorial: https://realpython.com/python3-object-oriented-programming/
- Python Decorators Guide: https://realpython.com/primer-on-python-decorators/
- Type Hints Documentation: https://docs.python.org/3/library/typing.html