Teaching the "range" function in Python 3

Chris Angelico rosuav at gmail.com
Thu Jun 29 22:57:47 EDT 2017


On Fri, Jun 30, 2017 at 12:33 PM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> A better *FIRST* example would be
> something like this:
>
>     def add(x, y):
>         return x + y
>
> When teaching a student about functions, the first step is
> to help them understand *WHY* they need to use functions,
> and the second is to teach them how to define a function. In
> my simplistic example, the practical necessity of functions
> can be easily intuited by the student without the
> distractions...

... except that you've made your first function so trivial that it
doesn't need to be a function. How does that help anyone understand
why they need functions? What's the point of writing "add(5, 7)"
rather than "5 + 7"? So you need something else around the outside to
justify even having a function at all.

In the example in the tutorial, the details ...

> ... of (1) doc-strings, (2) tuple unpacking, (3) an
> inner loop structure, (4) implicitly writing to IO streams
> using the print function, (5) using advanced features of the
> print function, (6) more tuple unpacking (this time with a
> twist of lime), (7) and an implicit newline insertion using
> the print function

don't need to be explained at all! They *just work*. You also don't
have to explain in detail how garbage collection works, the way that
Python's object and type models work, or how the electrons in your CPU
are kept from portalling across in a quantum tunnel. None of that
matters. So I support the tutorial's example over yours.

ChrisA



More information about the Python-list mailing list