Skip to content
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

Rename fib5.py variable 'next' which is builtin #4

Closed
gidven opened this issue Feb 23, 2019 · 1 comment
Closed

Rename fib5.py variable 'next' which is builtin #4

gidven opened this issue Feb 23, 2019 · 1 comment

Comments

@gidven
Copy link

gidven commented Feb 23, 2019

fib5.py in Chapter 1 uses the variable name "next", which is a builtin name and is best avoided in Python. Although less readable, I suggest renaming the variables to something like this:

def fib5(n: int) -> int:
    if n == 0: return n  # special case
    lst: int = 0  # initially set to fib(0)
    next: int = 1  # initially set to fib(1)
    for _ in range(1, n):
        lst, nxt = nxt, lst + nxt
    return nxt
@davecom
Copy link
Owner

davecom commented Feb 23, 2019

Thanks for bringing this to my attention. I regret the shadowing of the next() function here. Since the print edition has already been finalized, and it's not harmful for this toy example, we will be leaving it as-is, so as to keep all versions of the text in sync.

@davecom davecom closed this as completed Feb 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants