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
Update Doc/tutorial/introduction.rst
Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
  • Loading branch information
TommyUnreal and CaedenPH authored Jul 29, 2023
commit cdafb1fcb2cc22dbfc430b4cd30f944ac24f5350
2 changes: 1 addition & 1 deletion Doc/tutorial/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ from the Fibonacci series that are lower than 150::
>>> a, b = 0, 1
>>> 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
... 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
... a, b = b, a + b
...
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.


Expand Down
0