Quiz Catalog

Catalog of quizzes

def double_print(func):
  def wrapper():
    func()
    func()
  return wrapper

@double_print
def greeting(name):
  print(f'Hello {name}', end=' ')
  
greeting("Vladimir")
TypeError: wrapper() takes 0 positional arguments but 1 was given
  • decorator
  • function/inner

def double_print(func):
  def wrapper(*args, **kwargs):
    func(*args, **kwargs)
    func(*args, **kwargs)
  return wrapper

@double_print
def greeting(name):
  print(f'Hello {name}', end=' ')
  
greeting("Vladimir")
Hello Vladimir Hello Vladimir
  • decorator
  • function/inner

def outer():
  num = 5

  def inner():
    nonlocal num
    num = 25
    print(num, end = ' ')

  inner()
  print(num)

outer()
25 25
  • scope/nonlocal
  • function/inner

def outer(num):
  def inner(num1):
    return num + num1
  return inner

otr = outer(100)

print(otr(200))
300
  • function/inner

def outer():
  def inner():
    nonlocal num
    num = 25
    print(num, end = ' ')

  inner()
  print(num)

outer()
SyntaxError: no binding for nonlocal 'num' found
  • scope/nonlocal
  • function/inner

def outer():
  num = 5

  def inner():
    global num
    num = 25
    print(num, end = ' ')

  inner()
  print(num)

outer()
25 5
  • scope/global
  • function/inner

def outer():
  num = 5

  def inner():
    num = 25
    print(num, end = ' ')

  inner()
  print(num)

outer()
25 5
  • scope
  • function/inner