__str__ vs. __repr__

Charles Boncelet boncelet at udel.edu
Mon Nov 8 11:09:14 CET 1999


Tim Peters wrote:

> David Ascher suggested that str(long) drop the trailing "L", and that's a
> good example.  The "L" is appropriate for repr(), for so long as Python
> maintains such a sharp distinction between ints and longs, but is really of
> no help to most users most of the time.
On the dissenting side, I find the "L" useful (just as I find the
difference between 1 and '1' useful.  Consider the following:

>>> a,b = 2L, 2
>>> a,b
(2L, 2)
>>> a**32
4294967296L
>>> b**32
Traceback (innermost last):
  File "<stdin>", line 1, in ?
OverflowError: integer pow()

Without the "L", it is not at all clear why a**32 works and b**32 fails.

--Charlie

-----
Charles Boncelet <boncelet at udel.edu>
University of Delaware
Newark DE 19716 USA
http://www.eecis.udel.edu/~boncelet/




More information about the Python-list mailing list