Skip to main content
Loading page…
Python Mastery
Chapter 14
Lesson 1 of 4
Dunder (Magic) Methods
Contents
Notes
Tutor
Concept
What Are Dunder Methods?
Loading activity…
Previous
1 / 8
Continue
Contents
Notes
Discussion
Tutor
28 min
8 activities
0 of 8 done
In this lesson
1
What Are Dunder Methods?
2
__repr__ vs __str__: Know the Difference
3
Building a Vector Class Step by Step
4
Why __hash__ Must Accompany __eq__
5
repr vs str Quiz
6
Pitfall: Returning NotImplemented, Not Raising NotImplementedError
7
Implement __getitem__ and __contains__ on a Deck
8
Operator Overloading Reflection
Objectives
Implement __str__ and __repr__ to produce human-readable and unambiguous object representations
Override __eq__ and __hash__ to make objects work correctly in sets and as dict keys
Implement __len__ and __getitem__ to make objects behave like sequences
Overload arithmetic operators using __add__, __sub__, and friends on a Vector class
Chapter 14 · Advanced OOP
Dunder (Magic) Methods
Properties & Computed Attributes
Dataclasses
Abstract Base Classes & Enums
Previous: Memory, Reference Counting & __slots__
Next: Properties & Computed Attributes