8000 gh-107017: Rework the Fibonacci example by TommyUnreal · Pull Request #107132 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-107017: Rework the Fibonacci example #107132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better multichar end arg example in print().
  • Loading branch information
TommyUnreal committed Jul 23, 2023
commit 1fae12b644f9e328a50a3a51042cf6c773406f88
8 changes: 4 additions & 4 deletions Doc/tutorial/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,14 @@ Fibonacci series
----------------

Great! Now that we have the knowledge, let's write code to print all numbers
from the Fibonacci series that are lower than 1000.
from the Fibonacci series that are lower than 150.

>>> a, b = 0, 1
>>> while a < 1000:
... print(a, end=', ')
>>> while a < 150:
... print('', a, '', end='->')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this utilities the print sep param, however this is nor explained nor inferred, so to a beginner it may be confusing

Perhaps it could be beneficial to show off f-strings like

Suggested change
... print('', a, '', end='->')
... print(f'{a} ->', end='')

Or to keep end as ->

Suggested change
8000
... print('', a, '', end='->')
... print(f'{a} ', end="->")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very strongly prefer the original print('', a, '', end='->'), which reduces the punctuation the learner has to deal with to a minimum, and emphasises instead the connection between more easily assimilated things, like the English word "end" and the "arrow" ("->").

Showing off f-strings while demonstrating a different functionality introduces unnecessary cognitive burden. Two different kinds of quotes and two different kinds of brackets requires a lot of parsing and stopping. I don't think this is the right solution here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning: As this is an Introduction chapter, I wanted to keep the number of introduced concepts to the minimum. There are ways to code this better, but it is not formally wrong. The default separator is already shown in the example above and this just builds on that, so it's hopefully not confusing to the reader.

... a, b = b, a+b
...
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987,
0 -> 1 -> 1 -> 2 -> 3 -> 5 -> 8 -> 13 -> 21 -> 34 -> 55 -> 89 -> 144 ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I like the way that the example illustrates the value of using end - no need to explain, the example does it much more effectively. This will stick in someone's mind.


.. rubric:: Footnotes

Expand Down
0