Intermediate Python: Functions, Modules and Object-Oriented Programming
Intermediate Python (Functions, Modules, OOP) is an intermediate-level course of 5 lessons (about 3 h), with 15 exercises and 15 quiz questions. Prerequisites: Python Fundamentals. Exercises run in the browser, with nothing to install.
- Python
- Intermediate
- 5 lessons
- 3 h
- 15 exercises
- Exercises run in the browser
The course in brief
This course takes you from simple scripts to organized, reusable Python code. You master advanced parameters and annotations, higher-order functions and generators, organization into modules, then object-oriented programming through to dataclasses and custom exceptions. It is the essential foundation for data science and web development in Python.
What you will be able to do
- Design flexible and safe functions with *args, **kwargs, keyword arguments and annotations
- Use lambda, key= and generators to process data efficiently
- Organize a project into modules and packages and make use of the standard library
- Model a business domain with classes, methods and inheritance
- Simplify data classes with @dataclass
- Define and catch custom exceptions
Syllabus: 5 lessons
- Use *args and **kwargs to accept a variable number of arguments
- Enforce keyword-only arguments and avoid the mutable default value trap
- Annotate parameter and return types
- 02
Functions as Objects, Lambdas and Generators
- Pass a function as an argument, notably with the key parameter
- Write short lambda functions
- Create a generator with yield to process data on the fly
- 03
Modules, Packages and the Standard Library
- Import modules and functions in different ways
- Organize your code into modules and use `if __name__ == "__main__"`
- Make use of a few key modules of the standard library
Modules and importsStandard libraryVirtual environments and pip
- 04
Classes and Objects
- Define a class with __init__, attributes and methods
- Create and manipulate several independent instances
- Distinguish instance and class attributes and define __repr__
- 05
Inheritance, Dataclasses and Custom Exceptions
- Create a derived class that reuses and specializes a parent class
- Simplify data classes with @dataclass
- Define your own business exceptions
Final project
Lending Library Management Module
Design a small Python module that manages the loans of a media library. It must model documents (book, DVD) through inheritance or dataclasses, members and loans through composition, apply business rules (maximum number of loans, duration depending on document type, late penalties computed with datetime) and report violations with custom exceptions. A generator must make it possible to iterate over overdue loans.
Deliverables
- An organized `mediatheque.py` module, with type annotations and docstrings
- At least one class hierarchy with super() and an overridden method
- Dataclasses with field(default_factory=...) where needed
- A hierarchy of business exceptions (for example QuotaAtteint, DocumentIndisponible)
- A generator of overdue loans and a report function sorted with key=
- An `if __name__ == "__main__":` block containing a demo scenario and assertions
Assessment criteria
- Business rules are respected and tested with assertions
- Inheritance and composition are used appropriately
- Exceptions are specific, informative and caught at the right level
- The code is readable: explicit names, short functions, annotations and docstrings
- No classic pitfall (mutable default, shared class attribute) is present
Frequently asked questions
What level do I need for this intermediate Python course?
You need to know the basics of Python: variables, conditions, loops, lists, dictionaries and simple functions. These are covered by the Python Fundamentals course (PY1).
Is object-oriented programming useful in data science?
Yes. Libraries such as pandas and scikit-learn are built with classes: understanding objects, methods and inheritance helps you use them, read their documentation and write your own reusable code.
What is the difference between a class and a dataclass?
A dataclass is a regular class to which the @dataclass decorator automatically adds __init__, __repr__ and __eq__ based on the annotated attributes. It is ideal for objects whose main purpose is to store data.
Does this course prepare me for Django or FastAPI?
Yes, it covers their Python prerequisites: organization into modules and packages, classes and inheritance, type annotations and exceptions. These concepts are used constantly in web frameworks.
This course, told for your job
Say what you want to be able to do: “Intermediate Python (Functions, Modules, OOP)” takes its place in your path, with examples from your field. The concepts stay those of the course.