[Python-ideas] Floating point contexts in Python core
Oscar Benjamin
oscar.j.benjamin at gmail.com
Thu Oct 11 21:12:37 CEST 2012
On 11 October 2012 19:46, Guido van Rossum <guido at python.org> wrote:
> On Thu, Oct 11, 2012 at 11:42 AM, Oscar Benjamin
> <oscar.j.benjamin at gmail.com> wrote:
>> I've spent 4 hours this week in computer labs with students using
>> Python 2.7 as an introduction to scientific programming. A significant
>> portion of that time was spent explaining the int/float division
>> problem. They all get the issue now but not all of them understand
>> that it is specifically about division: many are putting .0s
>> everywhere. I expect it to be easier when we use Python 3 and I can
>> simply explain that there are two types of division with two different
>> operators.
>
> You could have just told them to "from __future__ import division"
I know but the reason for choosing Python is the low barrier to
getting started with procedural programming. When they're having
trouble understanding the difference between the Python shell and the
OS shell I'd like to avoid introducing the concept that the
interpreter can change its calculation modes dynamically and forget
those changes when you restart it. It's also unfortunate for the
students to know that some of the things they're seeing on day one
will change in the next version (you can't just tell people to import
things from the "future" without some kind of explanation).
I used the opportunity to think a little bit about types by running
type(x) and explain that different types of objects behave
differently. I would rather explain that using genuinely incompatible
types like strings and numbers than ints and floats though.
Oscar
More information about the Python-ideas
mailing list