Flow Control with If Statements (Theory of Python) (Python Tutorial)

preview_player
Показать описание
Let's look at control flow in imperative languages. In Python, we can use the if statement, along with the elif and else blocks, to control how the data should manipulate the program.

Thank you!
Рекомендации по теме
Комментарии
Автор

Here is the implementation of cache without branching :)

def cache(fn):
result = 0
fac = 1

def wrapper(n1, n2):
nonlocal result, fac
result += fac * fn(n1, n2)
fac = 0
return result
return wrapper

gibarian
Автор

Hello, I am really enjoying your serie on python. As a seasonned programmer in other langages I find it useful to learn the peculiarities of python.

For a solution without branching I thought about this one, it's not particularly clever but heh, it underlines setdefault function:

def cache(fn):
cache = { }
def wrapper(*args, **kwargs):
nonlocal cache
return cache.setdefault('cached', fn(*args, **kwargs))
return wrapper

romaingautier
join shbcf.ru