Skip to content
CodeKruPro

__str__, __repr__, __eq__ and __hash__

QuizMediumPython only

The double-underscore names are special methods (dunder methods) that Python calls for you. Class P defines __str__, __repr__ and __eq__ (comparing a field) but not __hash__. Which statements are true? Pick all that apply.

  • print(p) uses __str__
  • print([p]) uses __repr__ for the item
  • {P(1)} works and holds one object
  • P(1) == P(1) is True while P(1) is P(1) is False

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in