str()
is used for "pretty printing", but in the Python interpreter, you are more likely to want the background information such as the id of the object, what class it is, etc. (theoretically), and repr()
is used for that. If you run pydoc __builtin__.repr
, it says "For most object types, eval(repr(object)) == object." There are some types that are completely different, but whose __str__
method returns the same thing. For example, str(str(some_object))
is the same as str(same_object)
, so if I had a list, [0, 4, 5]
, and I printed it with str
, I would get [0, 4, 5]
. If I printed str(mylist)
with str()
, I would still get [0, 4, 5]
even though they are different types. With repr()
, however, str(mylist)
would be printed as '[0, 4, 5]'
which is more likely what I was looking for. Someone who is using the interpreter is probably testing something or debugging something, and he would want to know that it was a string, not really a list.