1. Home
  2. Data Science
  3. Python
  4. What does the nonlocal keyword do in Python?

Added 25 Nov 2026

What does the nonlocal keyword do in Python?

  1. Declares a global variable
  2. Creates a constant
  3. Refers to a variable in the nearest enclosing (non-global) scope Correct answer
  4. Imports a module

Correct answer

C. Refers to a variable in the nearest enclosing (non-global) scope

MCQSEXAM

Explanation

nonlocal lets a nested function rebind a variable of its enclosing function.

Reference

Asked in: Python Interview Functions

https://docs.python.org/3/tutorial/controlflow.html#defining-functions

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs