[Tutor] rep() and str(0
Thomas Rivas
trivas7@rawbw.com
Sun, 30 Jun 2002 09:49:46 -0700
On Sun Jun 30 2002 you wrote:
>>Firstly, I would like to know what exactly repr() does.
My understanding is that rep() is a built-in function that does the same
thing as the `` operator -- converts an object x to an expression string
(think REPResentation) that can be evaluated as a valid expression using the
eval() built-in function. The str() function (think STRing) converts an
object that is human-friendly that is usually used by the print statement.
I.e,:
>>>str(4.53-2j)
'(4.53-2j)'
>>>
>>>str(1)
'1'
>>>
>>>str(2e10)
'20000000000.0'
>>>
>>>repr([0, 5, 9, 9])
'[0, 5, 9, 9]'
>>>
>>>`[0, 5, 9, 9]`
'[0, 5, 9, 9]'
In my experience all three usually return the exact same string.
Tom Rivas