Want to Practise more and morePython Object Oriented Programming Exercises& concepts then you are at the right place.
This Book consist of 75 Python Object Oriented Programming coding exercises to practice different topics.
In each exercise we have given the exercise coding statement you need to complete and verify your answers. We also attached our own input output screen of each exercise and their solutions.
Learners can use their own python compiler in their system or can use any online compilers available.
We have covered all level of exercises in this book to give all the learners a good and efficient Learning method to do hands on python different scenarios.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A hands-on drill book with 75 Python OOP exercises that walks you from scope rules and namespaces through class design, instance attributes, and encapsulation—ideal for beginners who want to practice coding rather than just read theory.
【Book Arc】
- **Opening (~0%–6%)**: Introduces the book’s purpose—75 coding exercises with solutions and expected outputs—and starts with Module 1 on Python’s LEGB (Local, Enclosed, Global, Built-in) scope rules, including how to inspect function arguments and use `global`/`nonlocal` statements.
- **Early (~6%–25%)**: Covers namespaces and scopes (e.g., inspecting module and class `__dict__`), then moves into `*args` and `**kwargs` with exercises on flexible function signatures and conditional printing.
- **Early–Middle (~25%–44%)**: Shifts to core class mechanics—creating simple classes, checking types with `type()` and `isinstance()`, inspecting class and instance namespaces, and using `issubclass()` to verify inheritance from `object`.
- **Middle (~44%–56%)**: Focuses on class attributes—defining, reading, modifying, adding, and deleting them via dot notation, `getattr()`/`setattr()`, and `delattr()`, plus building class-level functions that describe or return attribute values.
- **Middle–Late (~56%–69%)**: Explores instance attributes—assigning them dynamically, comparing `__dict__` before and after assignment, looping over multiple instances, and creating instances from dictionary data.
- **Late (~69%–end)**: Continues with instance attribute patterns and likely moves into `__init__()`, visibility, encapsulation, and computed attributes (modules 7–10), though the excerpts only partially cover these later topics.
【Key Takeaways】
- **Scope rules are the entry point** (Opening): Exercises on `global` and `nonlocal` teach you how to modify variables from nested or outer scopes—a common Python gotcha that trips up beginners. (Early)
- **Inspect, don’t guess** (Early): Using `__dict__` on modules, classes, and instances reveals what Python actually stores, making namespaces tangible rather than abstract. (Early)
- **Flexible functions via `*args`/`**kwargs`** (Early): Exercises like building a `stick()` function that concatenates only string arguments show how to handle variable-length inputs and filter types. (Early)
- **Classes are objects too** (Early–Middle): Checking `type(Phone)` returns `<class 'type'>`, and `isinstance()`/`issubclass()` exercises reinforce that classes and instances live in the same object model. (Middle)
- **Class attributes are shared, instance attributes are personal** (Middle): The OnlineShop and Book exercises contrast class-level data (e.g., `sector`) with per-instance data (e.g., `author`), clarifying when to use each. (Middle)
- **Dynamic attribute management is a real skill** (Middle): Practicing `getattr()`, `setattr()`, and `delattr()` prepares you for metaprogramming and frameworks that manipulate objects at runtime. (Middle)
- **Instance attributes can be added on the fly** (Middle–Late): Assigning `book.author = 'Dan Brown'` after instantiation shows Python’s flexibility, and looping over instances to print `__dict__` builds debugging habits. (Late)
【Reading Tips】
- **Skim the intro and jump straight to exercises**—the book’s value is in the 75 problems, not the brief Python overview at the start.
- **Deep-read Modules 1–3** (scope, namespaces, args/kwargs) if you’re shaky on these; they’re foundational and appear in almost every real Python project.
- **Type out solutions, don’t just read them**—the expected outputs (e.g., `('company', 'country', 'price', 'currency')`) are precise, so verify your code matches exactly.
- **Watch for the `exercise.py` vs. `evaluate.py` note** in early exercises—it explains why `__module__` prints `exercise` instead of `__main__`, a subtle but important detail.
- **Use the later modules (7–10) for review** if you already know basics; the excerpts don’t detail `__init__()`, encapsulation, or computed attributes, so treat those as advanced practice.
【Coverage Limits】
This guide covers the first ~69% of the book (Modules 1–6) in detail; the later modules on `__init__()`, visibility, encapsulation, and computed attributes are only partially represented in the source excerpts.
Excerpt 1
ge for all critical platforms and can be freely distributed. Learning Python doesn't require any pre- requisites. However, one should have the elemental unde...
Expected result: Sport#sumer time#workout#gym Solution: 10. Implement a function called dispiay_info() which prints the name of the company (as shown below)...
solution that the user provides is in a file named exercise.py, while the checking code (which is invisible to the user) is executed from a file named evalua...
ectronics' sector_code = 'ELE' is_public_company = False 32. A class named OnlineShop was defined with the class attributes set accordingly: • Sector to the...
lled title. Create an instance of the Book class named book. Then, using the try ... except ... clause, try using the set_title()method to set the value of t...
l': 'Insignia', 'price': 115000, 'type_of_car': 'sedan'} 48. Implement a class called Car that sets the following instance attributes when creating an instan...
isplays the names of all private attributes of the instance. Then create an instance with the given arguments: • 'Acer' • 'Predator' • 'AC-100' • 5490 • 0.2...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Loading comments...
Reply to Comment
Edit Comment