Python non locale

Esempi di codice

11
0

variabile globale di accesso python

globvar = 0

def set_globvar_to_one():
    global globvar    # Needed to modify global copy of globvar
    globvar = 1

def print_globvar():
    print(globvar)     # No need for global declaration to read value of globvar

set_globvar_to_one()
print_globvar()       # Prints 1
5
0

N

def to_string(node):
    def actual_recursive(node):
        nonlocal a_str		# ~global, can modify surrounding function's scope.
        a_str += str(node.val)
        if node.next != None:
            actual_recursive(node.next)
    a_str = ''
    actual_recursive(node)
    return a_str
2
0

python non locale

def to_string(node):
    def actual_recursive(node):
        nonlocal a_str		# ~global, can modify surrounding function's scope.
        a_str += str(node.val)
        if node.next != None:
            actual_recursive(node.next)
    a_str = ''
    actual_recursive(node)
    return a_str

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
English
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................