Python by Swaroop C H - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

The repr function

The reprt function is used to obtain a canonical string representation of the object. Backticks (also called conversion or reverse quotes) do the same thing. Note that you will have eval(repr(object)) == object most of the time.

>>> i = []
>>> i.append('item') >>> `i`
"['item']"
>>> repr(i)
"['item']"

Basically, the repr function or the backticks are used to obtain a printable representation of the object. you can control what your objects return for therepr function by defining the__repr__ method in your class.

Find Your Next Great Read

Describe what you're looking for in as much detail as you'd like.
Our AI reads your request and finds the best matching books for you.

Showing results for ""

Popular searches:

Romance Mystery & Thriller Self-Help Sci-Fi Business