PEP0238 lament

Paul Prescod paulp at
Tue Jul 24 02:23:18 CEST 2001

David Eppstein wrote:
> Rather than arguing about nonexistent situations, let's make an analogy:
> In Python, "123"+"456" = "123456" but 123+456=579.  These are two different
> operators that happen to have the same symbol.  I really don't see why
> integer-division and floating-point-division should be treated any
> differently from this case.

Python encourages you to treat integers and floats as interchangable.

>>> "%d"%5.3
>>> math.sin(200)
>>> math.sin(200.0)==math.sin(200)
>>> 5+3.0==5+3
>>> 5*3.0==5*3
>>> 5/3.0==5/3

It is a nasty trick to lull a person into a sense of safety and then in
one corner of the language dash it away.

It is very common to pass floats to functions that expect integers and
vice versa without really thinking about it. It is *especially* common
to pass integers to functions that expect floats.

Strings are a totally different issue. The overloaded plus operator is
not at all confusing because strings and integers are such strongly
distinct types that you can almost never use them interchangably. If
Python *did* treat strings and integers interchangably (as Perl and Tcl
do) then it would be very bad if "+" meant string concatenation. In Perl
and Tcl, + does NOT mean string concatenation.
Take a recipe. Leave a recipe.  
Python Cookbook!

More information about the Python-list mailing list