Problem Statement
What is the usual difference between __str__ and __repr__?
Explanation
__repr__ should ideally return a string that could recreate the object or be precise for debugging. __str__ returns a user-friendly display.
If only __repr__ is defined, print will fall back to it. Good object printing improves debuggability.
Code Solution
SolutionRead Only
class P:
def __init__(self,x): self.x=x
def __repr__(self): return f'P(x={self.x})'
def __str__(self): return f'Point {self.x}'