Bizarre behavior with mutable default arguments

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Dec 30 19:01:23 EST 2007


On Sun, 30 Dec 2007 13:34:07 -0800, Dennis Lee Bieber wrote:

> On Sun, 30 Dec 2007 12:11:50 -0800 (PST), bukzor
> <workitharder at gmail.com> declaimed the following in comp.lang.python:
> 
> 
>> Just because it's well known doesn't mean we shouldn't think about it.
>> For example, in the same list you linked, "3. Integer division" is
>> being fixed in py3k.
>>
> 	IMHO -- Py3K is /breaking/ integer division... as the division of
> two integers will differ from what happens in all the other languages I
> have used... All the others, to get a floating result from dividing two
> integers requires one to explicitly convert at least one term to a float
> first

You need to use more languages :)

Prolog uses / for division and // for integer division, just like Python.

Apple's Hypertalk (and derivatives) don't distinguish between integer and 
floating point division. The / operator returns an integer result if the 
floating point result happens to be an integer.

e.g. 10.0/5.0 => 2 while 11.0/5.0 => 2.2)

I believe that Javascript behaves the same way.

According to this table here:
http://msdn2.microsoft.com/en-us/library/2hxce09y.aspx

VisualBasic uses / for floating point division and \ for integer 
division, and both JScript and Visual FoxPro don't even offer integer 
division at all.

No doubt there are others...



> -- as I would do with the current Python. The forthcoming change
> is going to require one to remember that if they want an integer result
> from two integers, they must use a different operator instead.

How is that different from needing to remember to use a different 
algorithm if you want a floating point result?



-- 
Steven.



More information about the Python-list mailing list