Python · Lesson 12.3 · Pro

Special methods

Make your objects print nicely, compare, sort and work with len().

In this lesson

  1. __repr__: how an object prints
  2. __str__: the friendly version
  3. __eq__ and __lt__: compare and sort
  4. __len__ and more