On 2 Oct 2012 23:17, "boB Stepp" <robertvst...@gmail.com> wrote:

<snip>

> I am puzzled by the results of the following:
>
> >>> x = "Test"
> >>> x
> 'Test'
> >>> print(x)
> Test
>
> I understand that 'Test' is the stored value in memory where the
> single quotes designate the value as being a string data type. So it
> makes sense to me that just typing the object reference for the string
> results in including the single quotes. But why does the print() strip
> the quotes off? Is just as simple as

Hi boB,

Under the covers, in python 2.x, print x causes the human readable string
representation of x to be output by calling x.__str__. In an interactive
prompt, typing x displays the python representation of x by calling
x.__repr__.  These can be the same or quite similar or quite different.
When possible, __repr__ special methods ought to be defined so x equals
eval(x.__repr__()).

I believe, but don't warrant that in this regard python 3.x behave like 2.x
(modulo the difference in the print syntax).

Best,

Brian vdB
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to