Next / Previous / Contents / TCC Help System / NM Tech homepage

21.17. repr(): Representation

The repr function attempts to convert any value to a string. Unlike the str() function, it attempts to display the value in Python source form, that is, in a form suitable for passing to eval() (see Section 21.6, “eval(): Evaluate an expression in source form”). It works the same as the `...` operator. Examples:

>>> s='Wensleydale'
>>> print s
Wensleydale
>>> print str(s)
Wensleydale
>>> print repr(s)
'Wensleydale'
>>> print `s`
'Wensleydale'

To specify the behavior of the repr() when it is applied to an instance of a user-defined class, see Section 26.3.19, “__repr__(): String representation”.