python keep value recursive function

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

Here is what the above code is Doing:
1. Define a function that takes a node as an argument.
2. Define a nonlocal variable a_str.
3. Append the node’s value to a_str.
4. If the node has a next node, recurse on the next node.
5. Define a function that takes a node as an argument.
6. Define a global variable a_str.
7. Append the node’s value to a_str.
8. If the node has a next node, recurse on the next node.
9. Return a_str.