On Mon, Jul 12, 2010 at 6:36 PM, Paul Rubin <no.em...@nospam.invalid> wrote: > There is a horrible (IMO) thing that Perl, Lua, and Javascript all do, > which is automatically convert strings to numbers, so "12"+3 = 15. > Python has the good sense to throw a type error if you attempt such an > addition, but it goes and converts various types to bool automatically, > which is more Perl-like than I really enjoy. In fact Python 3 added yet > another automatic conversion, of int to float on division, so 1/2 = 0.5. > > Obviously it's a point in the design space where various decisions are > possible, but I can get behind the "explicit is better than implicit" > idea and say that none of those conversions should be automatic, and if > 1/2 = 0 was confusing people in Python 2 enough to justify changing > divison semantics in Python 3, the preferable change would be for int > division to raise TypeError rather than quietly converting to float.
I don't think it's any more egregious than automatic conversions of mixed-type expressions, such as 3 + 4.5. If you don't want your ints automatically converted to floats on division, then use the integer division operator. 1 // 2 is still 0 in Python 3. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list