Error in Python program: variable not defined __python

Source: Internet
Author: User
The wrong kinds of Python programs

There are two kinds of errors in Python programs. One is syntax errors (syntax error). This error is that the writing of the statement does not conform to the grammatical rules of the Python language. The second is a logical error (logic error). This error refers to the program can run, but the function does not meet expectations, such as "wrong" situation.

error not defined by variable

In a python program, variables need to be defined before they are used. If this is not done, the variable does not have a defined error. This is a grammatical error. In Pycharm, syntax errors are marked with red wavy lines, as shown in Figure 1.

Figure 1 Pycharm, syntax errors are marked with red wavy lines

error message run by Python program

In Pycharm, the program runs an error, and the error message is reported in the Run window (that is, the input data or the Output window). By forcing the example of Figure 1, the error message shown in Figure 2 will be rendered.

The error message is reported in the Run window below Figure 2

Error message, the display lists the program's running trajectory (traceback). Here, the running trajectory is not long, you will encounter a very long situation. There is only one running trajectory that indicates the 3rd line (lines 3) in the file 2-2-5-varerror.py, the content is "print (mesage) #mesage的拼写错了, missing an S", there is an error. The file path is a blue font program that indicates that it is a hyperlink, and clicking on it lists the line code and the code nearby.

At the end of the error message, the wrong conclusion is given, Nameerror:name ' mesage ' is not defined. The name is wrong: The variable name ' mesage ' is undefined.

Learn to analyze error messages for Python programs. Although it is in English, you will catch the essentials if you read more. Using error messages, you can quickly locate errors and correct errors.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.