The nonlocal Keyword in Python PRO

Python 3.0 introduces the nonlocal new reserved word. Using this new reserved word we can assign directly to a variable with the same name in the outer scope (instead of creating a new variable).

def a():
    temp = 2
    def b():
        nonlocal temp
        temp = 4
        print("temp inside b ",temp)
    b()
    print("temp inside a ",temp)
a()

The following video clip explains a short code sample that uses the nonlocal reserved word.

Share:

banner for the css playlist in hebrew life michael courses for programmers

The First Steps in CSS

Learn CSS using our our videos (in Hebrew) on the CSS (he) playlist on youtube. Do it now. Do it for free.

Good Trainers Collaborate with Others

It is always essential to keep an open mind and learn from others. This applies to everyone, including teachers and especially software development trainers. Software

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences