Error Python program: Variable is undefined (NameError: name 'mesage' is not defined.)

Wrong kind of Python programs

Error Python program in two ways. One is a syntax error (syntax error). This error is defined grammar written statement does not comply with the Python language. The second is a logical error (logic error). This error means that the program can run, but the function does not meet expectations, such as "miscalculated" the situation.

 

Undefined variable error

Python programs, the need to define the variables to use later. Failure to do so, the variable is undefined error occurs. It belongs to a syntax error. Pycharm, the syntax error marked with a red wavy line out, as shown in FIG.

image

Pycharm FIG. 1, a syntax error is marked out with a red wavy line

 

Error message Python program run

Pycharm, the run error, and will run in a window (or window output data, i.e., input) of the error report information. Examples of forced operation of FIG. 1, an error message will appear as shown in FIG. 2.

image

2 Run window below the figure reported error message

 

Error message, the display shows the running track program (Traceback). Here, the running track is not long, it will encounter a very long case. Only a running track, pointed out that the line (line 3) file 2-2-5-varError.py in the third, the content is "print (mesage) #mesage spelling mistake, missed a s", there is an error. File Path with blue font program, indicating that it is a hyperlink, click on it, on top of the editor lists the lines of code and its nearby code.

 

The last error message is given to the wrong conclusion, NameError: name 'mesage' is not defined is translated into Chinese, the name wrong: variable name 'mesage' is not defined.

Released nine original articles · won praise 27 · views 90000 +

Guess you like

Origin blog.csdn.net/szw_yx/article/details/79053138