What is the use of the dunder __repr__ in the str(string) class ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the use of the dunder __repr__ in the str(string) class ?

Kindly explain how __repr__ works exactly !

13th Jun 2021, 7:54 AM
ch Murali
2 Answers
+ 2
__repr__ is used by repr global function: it is used to return the representation of the object/value (an alternate way from the str way): https://www.geeksforgeeks.org/str-vs-repr-in-JUMP_LINK__&&__python__&&__JUMP_LINK
13th Jun 2021, 7:57 AM
visph
visph - avatar
0
ch Murali , python.org has the definitive information on every Python language feature, but its self-search is usually useless and returns 0 results for __repr__. Instead, use a site search from an external search engine. I just pasted the following into DuckDuckGo and got a bunch of links directly to specific pages on python.org. site:python.org __repr__ Another option, and the one I use most often is to go to the general index page on python.org and alphabetically drill down to the thing you're after. Everything's there, including __repr__. https://docs.python.org/3/genindex.html
14th Nov 2023, 10:04 PM
Rain
Rain - avatar