python closure closure

The principle of python closure is the same as JavaScript closure,
but in python, you need to modify the external variable in the internal function and modify it with a nonlocal variable
. External variables are used, but this external variable is safe and not global.
insert image description here
insert image description here
Closures in JavaScript, the core also refers to global variables, but this global variable cannot be modified by others, but can only be modified by internal functions.

Guess you like

Origin blog.csdn.net/u013400314/article/details/131261937