CoursePython from Scratch to Intermediate · Module 9: Classes and Objects · part 62 of 75
Part 62 · Module 9: Classes and Objects

Lesson 3: Special methods: objects that print, compare and add

16 min read·14 Oct 2026
Module 9 · Lesson 3 · About 50 minutes · Needs: Module 9 Lessons 1 and 2 (classes, __init__, self, methods), Module 8 Lesson 1 (raising an error), Module 3 Lesson 3 (f-strings)

The situation

Amira prints the books that are out and gets <booknook.models.Book object at 0x...>. "I cannot read that," she says. "And why are two records of Frankenstein different books?"

Your classes hold the right data, but Python does not know how to show, compare or count them. This lesson teaches them print, ==, <, len, in, for and +. Jonah's Frankenstein, B06, on loan as L04 and 16 days late today, runs through the lesson.

BEFORE: PRINT(FRANK) AFTER: PRINT(FRANK) <booknook.models.Book object at 0x...> Frankenstein by Mary Shelley
Before this lesson a Book prints as a memory address (red, unreadable); after it, the same print gives Amira the title and author (green).

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.