Quick actions

cmd+k|ctrl+k

Navigation

Languages

Python Web - L03

Snippet info

Language

Python

Visibility

public

Author

victormakwaitat

Created

2025-02-05T01:18:04.027185Z

Updated

2025-02-05T03:05:09.668008Z

import dis  # import dis to convert to byte code, push and pop example
def fib(n): # Python 3.6 above is 2 bytes
    if n <=2:
        return 1
    print(id(fib))
    return fib(n-1) + fib(n-2)
#dis.dis(fib)
fib(5)
print(fib(6))

def fib1(n):
    if n <= 3:
        return n
    current, second = 0, 1
    while n:
        current, second = second, current + second #current = second; second = current + second
        #temp = second
        #second = current + second
        #current = temp
        n -= 1
    return current
dis.dis(fib1)
print(fib1.__code__)
print(fib1.__code__.co_consts) # __code__ = internal system variable
print(fib1.__code__.co_varnames)
print(fib1.__code__.co_code)
print(dir(fib1))
INFO