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:

The Visitor Design Pattern

The Visitor Design Pattern

The visitor design pattern allows us to add operations to objects that already exist without modifying their classes and without extending them.

What are Anti Patterns?

Anti Patterns

Unlike design patterns, anti patterns just seem to be a solution. However, they are not a solution and they cause additional costs.

Virtual Threads in Java Professional Seminar

Virtual Threads in Java

The use of virtual threads can assist us with improving the performance of our code. Learn how to use virtual threads effectively.

NoSQL Databases Courses, Seminars, Consulting, and Development

MongoDB Design Patterns Meetup

The use of MongoDB involves with various cases in which we can overcome performance issues by implementing specific design patterns.

The Beauty of Code

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

Update cookies preferences