Python 3 Deep Dive Part 4 Oop 'link' (2026)

This write-up constitutes Part 4 of the Python 3 Deep Dive series, focusing exhaustively on Object-Oriented Programming (OOP).

While introductory courses teach the syntax of classes and objects, a "deep dive" requires understanding the underlying machinery: how attributes are stored, how method resolution works, how data encapsulation is actually enforced (or not), and the architectural patterns enabled by Python's dynamic nature.


Chapter 9 — The Lesson

Months later, Lina's library system hummed in production. The code was readable, well-tested, and adapted easily to new media types. She learned that OOP in Python is a set of practical tools: classes and objects map concepts; composition and small interfaces keep code flexible; special methods make types behave like built-ins; and dataclasses plus typing make intent explicit.

She closed the book, placed the bookmark back at "Part 4 — OOP," and wrote a small note beneath: "Prefer clarity; optimize only when needed." Outside, the rain had stopped. Lina walked to the library, unlocked the door, and let the morning light fall across a tidy shelf of objects—real and in code. python 3 deep dive part 4 oop

7.3 Using __slots__ for Memory Efficiency

class Point:
    __slots__ = ('x', 'y')
    def __init__(self, x, y):
        self.x = x
        self.y = y
  • Without slots: each instance has __dict__ (~72 bytes overhead)
  • With slots: fixed attributes, less memory, faster access, but no dynamic attributes.

9.2 Method vs Function

Methods are functions that receive self implicitly. Bound methods are callable objects.

class Foo:
    def bar(self): pass

print(Foo.bar) # <function Foo.bar at ...> print(Foo().bar) # <bound method Foo.bar of ...>

3.2 super() Beyond Simple Parent Calls

super() does not call the parent class. Instead, it delegates to the next class in the MRO.

class Logger:
    def log(self, msg):
        print(f"LOG: msg")

class Timestamp(Logger): def log(self, msg): print(f"[time.time()] ", end="") super().log(msg)

class Uppercase(Logger): def log(self, msg): super().log(msg.upper()) This write-up constitutes Part 4 of the Python

class MultiLogger(Timestamp, Uppercase): pass

ml = MultiLogger() ml.log("hello") # Output: [1734567890.0] LOG: HELLO

The MRO of MultiLogger is (MultiLogger, Timestamp, Uppercase, Logger, object). super() follows this chain.