The repr Function


A Byte of Python 

Go to the Table of Contents. Visit the Gifcom web site.

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 the repr function by defining the __repr__ method in your class.

Summary

We have covered some more features of Python in this chapter and yet you can be sure we haven't covered all the features of Python. However, at this stage, we have covered most of what you are ever going to use in practice. This is sufficient for you to get started with whatever programs you are going to create.

Next, we will discuss how to explore Python further.