# 5 examples of 'fibonacci series in python without recursion' in Python

Every line of 'fibonacci series in python without recursion' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure. ## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``6def test_fib(self, func):7    result = []8    expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]9    for i in range(len(expected)):10        result.append(func(i))11    assert_equal(result, expected)12    print('Success: test_fib')``
``14def fibonacci(x: int):15    if x &lt; 0:16        return -117    if x == 0:18        return 019    cache =  * (x + 1)20    for i in range(1, len(cache)):21        cache[i] = -122    cache = 123    return fibonacci_recur(x, cache)``
``6def py_fibonacci(n):7    """https://stackoverflow.com/a/52133289/2536357"""8    i = 09    nextterm = 110    present = 111    previous = 01213    while i &lt; n:14        nextterm = present + previous15        present = previous16        previous = nextterm17        i = i + 11819    return nextterm``
``37@tasklets.tasklet38def fibonacci(n):39  """A recursive Fibonacci to exercise task switching."""40  if n &lt;= 1:41    raise tasklets.Return(n)42  a = yield fibonacci(n - 1)43  b = yield fibonacci(n - 2)44  raise tasklets.Return(a + b)``
``6def fibonacci_partial_sum_naive(from_, to):7    if to &lt;= 1:8        return to910    previous = 011    current = 11213    for _ in range(from_ - 1):14        previous, current = current, previous + current1516    sum = current1718    for _ in range(to - from_):19        previous, current = current, previous + current20        sum += current2122    return sum % 10``