nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Mock Interviews
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

Questions
11 of 19
1How would you make a custom class usable in a for loop?
2How do __enter__ and __exit__ work together to implement the context manager protocol?
3How does Python implement inheritance, and what is the Method Resolution Order (MRO)?
4What are dataclasses, and how do they reduce boilerplate compared to manually writing __init__, __eq__, and __repr__?
5What is the @property decorator, and what problem does it solve compared to plain getter/setter methods?
6What is the difference between method overriding and method overloading, and why doesn't Python natively support overloading?
7What problem does the diamond inheritance pattern cause, and how does Python's MRO resolve it?
8What is the difference between a class and an instance in Python?
9How does Python implement encapsulation given that it has no true 'private' access modifiers?
10What is the purpose of self in instance methods, and why must it be explicitly declared in Python?
11What is the difference between __str__ and __repr__, and what convention should __repr__ follow?
12What is a metaclass, and what is type's relationship to every class in Python?
13What is the purpose of __eq__ and __hash__, and why must they be implemented consistently?
14What is a descriptor, and how do @property and ORMs like Django's models rely on the descriptor protocol?
15What is the difference between an instance method, a class method, and a static method?
16What is composition, and why is 'favor composition over inheritance' often recommended?
17What are dunder (magic) methods, and how do they enable operator overloading?
18When would you use a metaclass instead of a class decorator or __init_subclass__?
19How do abstract base classes (abc.ABC) enforce interface contracts in Python?
PythonPython
Basics
Control Flow and Functions
Data Structures
Comprehensions & Functional Programming
Iterators, Generators & Decorators
Object-Oriented Programming
Exception Handling & Debugging
Concurrency & Parallelism
Performance & Optimization
Testing
Security
Modules, Packaging & Environment
Type Hinting & Modern Python
System Design & Architecture with Python
Best Practices & Design Patterns
Edge Cases & Tricky Interview Questions
11 / 19

What is the difference between __str__ and __repr__, and what convention should __repr__ follow?

Difficulty: 5/10
Str, Repr, Dunder Methods

repr is for developers and should be unambiguous; str is for users

The convention is that repr produces an unambiguous, ideally evaluable representation aimed at developers, while str produces a readable, human-facing string. If str is not defined, Python falls back to repr. The interactive prompt, containers, and logging with %r use repr; print() and str() use str. A good repr looks like a constructor call and includes the essential state. For containers, the elements are shown with repr, which is why implementing repr properly makes debugging much easier.

  1. 1

    Follow the principle: eval(repr(obj)) == obj whenever it is practical and safe.

  2. 2

    Never put sensitive data such as passwords or tokens in repr, because repr shows up in logs and exception tracebacks.

  3. 3

    Trade-off: a faithful repr with all fields can be verbose; truncate long collections or large blobs deliberately.

  4. 4

    Common mistake: implementing str only and wondering why lists and dicts show an unhelpful object address.

  5. 5

    Common mistake: making repr raise, which can break debugging, logging, and error reporting.

  6. 6

    Version note: the fallback from str to repr has always existed. f-strings and format() use format, which defaults to str.

javascript

Scenario Questions

0-2 years experience

  1. 1Why does printing a list of your objects show <object at 0x...>?
  2. 2Which dunder is used by the interactive interpreter when you type an object and press Enter?

2-5 years experience

  1. 1You want repr(obj) to be safe and informative for a class holding a large DataFrame. How do you truncate?
  2. 2Your __repr__ accidentally includes a password field and it shows up in logs. How do you fix it?

5-8 years experience

  1. 1You need a repr that is evaluable for debugging but must not expose internal mutable state. How do you reconcile these?
  2. 2You are implementing __format__ alongside __str__ and __repr__. What precedence should each have?

8+ years experience

  1. 1Design a repr policy for a large domain model library that is safe, stable across versions, and useful for post-mortem debugging.
  2. 2Explain how repr interacts with pickling, caching, and equality in a framework where representations are used as identifiers.

Follow-up Questions

  • What happens if __str__ is missing and you call print(obj)?
  • Why does logging with %s behave differently from logging with %r for your objects?
Sharethis question

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.