Difference between __str__ and __repr__ in python?



Difference between __str__ and __repr__ in python?..

Answer / Siddhartha Singh Tomar

In Python, both `__str__` and `__repr__` are special methods used for string representation of objects. However, their purpose differs slightly:nn- `__str__` is designed to return a user-friendly string representation of an object that can be easily read by humans.n- `__repr__` is intended to return a string that, when evaluated, will recreate the exact object. It's primarily used for debugging purposes.n

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Should I learn c before python?

1 Answers  


What does “list comprehension” mean? How does it work and how can I use it?

1 Answers  


Is python scripting easy to learn?

1 Answers  


How to create a unicode string in python?

1 Answers  


How does python handle memory management?

3 Answers  


Which software is best for python programming?

1 Answers  


What are static methods for?

1 Answers  


What is the usage of enumerate () function in python?

1 Answers  


Python list of lists, changes reflected across sublists unexpectedly

1 Answers  


What is the difference between range() and xrange() functions in python?

1 Answers  


How to check whether a module is installed in python?

1 Answers  


Is python a scripting or programming?

1 Answers  


Categories