Are Python function can be used in a global variable?

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

Python function of variables, you can either use local variables (variables local name space), you can use global variables (variables global name space), functions, first look in local variables when performing a lookup variable read-only, can not be found to re-found global variable lookups. So when the local and global variables have the same variable names, function is to use local variables, local variables only when there is no corresponding variable will be global variables.
When the default variable assignment inside the function for the new variable definition, but Python function also supports the use of global variables, but before using the need to use global variables declared as a global variable, the syntax:
global global variable names

Details refer to "Section 5.4 Python function variables and scope"

Old ape Python, with the old ape learn Python!
Blog address: https: //blog.csdn.net/LaoYuanPython

please support, thumbs up, comment and processing concern! Thank you!

Guess you like

Origin blog.csdn.net/LaoYuanPython/article/details/94907748