How python uses repr
This article will explain in detail how python uses repr. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Repr
When defining a class or object in Python, it is useful to provide an "official" way to represent the object as a string.
For example:
> file = open ('file.txt', 'r') > print (file)
This makes debugging code easier. Add it to your class definition, as follows:
Class someClass: def _ _ repr__ (self): return "" someInstance = someClass () # print print (someInstance) this is the end of the article on "how python uses repr". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.