First, the cause of the problem
Defines a variable outside a function, and then use the following variables inside a function in python, and change its value, the result error local variable ‘a’ referenced before the assignment, the code is as follows:
error reason: the python functions and global variables with the same, if you have to modify the value of the variable will become a local variable, the reference to the variable nature can appear not to define such a mistake.
Second, the solution
The problem is solved by declaring a as a global variable with the global keyword:
Read More:
- Python global variables and global keywords
- Global variable error: unboundlocalerror: local variable ‘l’ referenced before assignment
- Python error: local variable ‘XXXX’ referenced before assignment
- Differences between using VaR and omitting VaR to define variables in JS
- Go start error: Panic: runtime error: invalid memory address or nil pointer reference
- Error: global variable is ambiguous (conflict between using namespace STD and global variable)
- Idapython: the solution of importing “site” failed error
- C + +: error in X utility file
- Can’t find Python executable “D:\python3\python.exe”, you can set the PYTHON env variable.
- Error c2143: syntax error: missing ‘;’ before ‘type’
- Linux GCC compilation error: “collect2: LD returned 1 exit status”
- Mounriver studio error handling
- MySQL 8 — error in setting simple password error 1819 (HY000): your password does not satisfy the current policy requirements
- Solve the problem of Python in Windows environment: Fatal error in launcher: Unable to create process using’”‘ in pip installation
- Analysis of the causes of errors in G + + compilation “was not declared in this scope”“
- Attempted import error: ‘injectglobal’ is not exported from ‘styled components’
- Node configuration environment variable and global installation of webapck
- Solve the problem that the tray of electron system disappears automatically
- Vue element admin configure global styles
- Configuration of OpenGL under CodeBlocks and solutions to problems encountered