Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pytest a nice Fibonacci example

This is a nice implementation of the Fibonacci function. If we look at the way we can use it we see that it works well for 10.

def fib(n):
    a, b = 1, 1
    for _ in range(1, n):
        a, b = b, a+b
    return a

from fibonacci import fib

print(fib(10))

Output:

55