What is the difference between `__str__` and `__repr__` methods in Python?

Answer Posted / nashiinformaticssolutions

`__str__` is used for creating a user-friendly string representation of an object. `__repr__` is used for creating a detailed string representation of an object, intended for debugging.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain about pickling and unpickling?

647


What is pickling and unpickling in python?

631


What is the dictionary in Python?

675


Do you need classes in python?

587


What is design pattern in python?

590


How to convert a list into a set?

617


How to call an external command in python?

666


Are strings mutable in python?

615


What does pep8 refer to?

600


Write a code to display the current time.

596


What are the programming-language features of python?

634


What is raise keyword do in python exception handling?

644


Is python string mutable?

603


Does range start at 0 python?

586


What is difference between sort and sorted in python?

629