PYTHON – Master Python OOP Programming with One Guide Only! A lot of Coding, Practice and Theory Learn Python with Hands-On Projects by Sekuloski Rick

PYTHON – Master Python OOP Programming with One Guide Only! A lot of Coding, Practice and Theory Learn Python with Hands-On Projects by Sekuloski Rick

Author:Sekuloski, Rick
Language: eng
Format: epub
Published: 2022-08-20T00:00:00+00:00


But there is better way of accessing variables that are declared outside the function and we know this syntax because we have used it before:

This is what we were doing so far, we passed the global variable x as an argument on line 8 and we can use it in the function body through parameter x. This is much better than using the global keyword inside the function, right?

Python nonlocal Keyword

The non-local keyword was added in Python 3 and can be explained if we use nested functions, therefore we need to go over the following example:

# nonlocal

def outer_fn():

x = 'John'



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.