Logo

  • home link icon Home
  • manual link icon Manual
  • blog link icon Blog
  • about link icon About
  • contact link icon Contact

Article Note | built-in python magic-method data-structure



magic-method

Python - Magic Method __eq__ - Implement custom object comparison

Magic Method __eq__ specify what should be compared to determine equality between two class instances. So it means that the __eq__ magic method allows you to define custom behavior for the == operator.

This method is accepting argument (most often called other) that is a class instance that is being compared.

Note | built-in python magic-method

Python - Magic Method __repr__ - Define object debug representations

The magic method __repr__ provides a way to return a string that represents an instance of a class.

Unlike __str__, which is meant to give a human-readable description, __repr__ is used to provide a string that could ideally be used to recreate the object.

Note | built-in python magic-method

Python - Magic Method __str__ - Create human-readable object representation

Magic Method __str__ specify what should be returned when we will call str() or print() on our class instance. This method needs to return a string.

It should return human-readable representation of your class. It is meant to help you understand better given object that you are working with.

It shouldn't be confused with __repr__ magic method. The __repr__ method, by contrast, is intended for a more developer-focused, technical representation.

Note | built-in python magic-method
  • 1

Menu

  • home link icon Home
  • manual link icon Manual
  • blog link icon Blog
  • about link icon About
  • contact link icon Contact

Article Note | built-in python magic-method data-structure

Created with ❤ by me, for you!
BLOCK of BYTES - Bite-sized coding lessons for busy developers
© 2025 www.DevCuriosity.com
DevCuriosity Logo
home link icon