Toggle

Steven D'Aprano steve at pearwood.info
Thu Oct 9 06:56:29 CEST 2014


On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote:

>>>> Color.Red
> <Color.Red: 0>
>>>> print (Color.Red)
> Color.Red
> 
> # Not sure what to make of that distinction...

That's because the interactive interpreter displays the repr() of objects 
(except for None, which it suppresses), while print outputs the str() of 
them.

py> class Test:
...     def __repr__(self): return "repr"
...     def __str__(self): return "str"
... 
py> x = Test()
py> x
repr
py> print(x)
str

That's an old, old part of Python, going back to Python 1.5 or older, if 
I remember correctly.



-- 
Steven



More information about the Python-list mailing list