This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: function definition tutorial encourages bad practice
Type: enhancement Stage: resolved
Components: Documentation Versions:
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: aisaac, berker.peksag, docs@python, terry.reedy
Priority: normal Keywords:

Created on 2014-02-03 05:09 by aisaac, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg210077 - (view) Author: Alan Isaac (aisaac) Date: 2014-02-03 05:09
Section 4.6 of the tutorial introduces function definition:

The first example defines a function that *prints* a Fibonacci series.

A basic mistake made by students new to programming is to use a function to print values rather than to return them.  In this sense, the example encourages bad practice and misses an opportunity to instruct.  Since they have already met lists in Section 3, I suggest that returning a list of the values and then printing the list would enhance the tutorial.
msg210657 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-02-08 15:00
There is a later example introduced by "It is simple to write a function that returns a list of the numbers of the Fibonacci series, instead of printing it:" that does exactly what you suggest.
msg266796 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-06-01 03:17
I agree with Terry. The print example is also useful to show the implicit return value of fib(). Quoting from the same section:

    [...] In fact, even functions without a return statement do return a value, albeit a rather boring one. This value is called None [...]
Date User Action Args
2022-04-11 14:57:58adminsetgithub: 64695
2016-06-01 03:17:27berker.peksagsetstatus: open -> closed

nosy: + berker.peksag
messages: + msg266796

resolution: not a bug
stage: resolved
2014-02-08 15:00:17terry.reedysetnosy: + terry.reedy
messages: + msg210657
2014-02-03 05:09:47aisaaccreate