Skills101
← All practice quizzes

Quiz: Scope and Closures

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

How Python finds a variable (the LEGB rule), what global and nonlocal really do, how closures remember values, and keyword-only, positional-only and unpacked arguments.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    In which order does Python search for a name?

  2. Question 2

    What does this print?

    x = 1
    def f():
        x = 2
        def g():
            return x
        return g()
    print(f())
    
  3. Question 3

    What does this print?

    def make():
        n = 0
        def step():
            nonlocal n
            n += 5
            return n
        return step
    s = make()
    s()
    print(s())
    
  4. Question 4

    What error do you get if an inner function does count += 1 on an enclosing variable without nonlocal?

  5. Question 5

    What is a closure?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →