When Python Attacks 1OF 3

zhaozj2021-02-16  82

In this article, I will record some errors that Python will be committed, and they will help you work.

First of all, I want to explain that these examples are the first-hand information, which is I obtained from the process of Python. In the past seven years, I am fortunate to mobilize more than 100 Python courses, giving more than 1,000 students - and see most of their mistakes. That is, the following example is how I think about the real Python beginner. In fact, these errors are wrong to commit incidents in beginner Python.

"What do you say?" You may ask, "Do you also commit so many errors in Python?" Yes, Python may be the simplest and most flexible programming language. But it still has grammar, data type, and some uncommon places.

From a good one, once you learn Python, many defects have been avoided, this is due to a concise language. There is very little interaction between the various parts of Python, which makes the opportunity that BUG appear. When you have a mistake, Python's Runtime Error discovery and reporting mechanism will help you get rid of faster from the error.

But Python programming is not completely worried, I am pre-prompting everyone here to prepare everyone. Let us now enter the three parts of the key issue to classify the error into an error, encoding error, and design errors.

Execute error:

Let us start from the most basic, and the error always comes with people just learned, even before they go deep into the grammar. If you have made some programming exercises, then these errors look very simple, but if you have not made, you may feel that it is not true.

1. Programming at Python Tips

You can program it under the prompt >>>. In Emacs, LS or EDIT, enter >>> is not very rare, but it is not "Python" programming. There are many ways to call system commands (such as Os.System, Os.Popen), but directly commands with the SHELL or some differences. If you want to execute a Python file, use Import File, don't use Python file.py under the shell, emacs.

2. Print important information in the file

Because the interactive prompt is automatically printed, you can save some Print statements. This is a good feature, but you have to remember that in the Python file, you must use the print out important information to observe the output.

3. Note the extension under Windows

If you use NotePad to program, remember when you save, select All Files. And to explicitly give the extension of the file "xxx.py". Otherwise, NotePad will automatically store the file into TXT type. Worse, Word and WordPad will add Python unrecognized formats. Therefore, the first principle should pay attention to select All Files. Or a better IDLE, in the idle, you should also pay attention to the explicit presentation .py extension.

4. Windows Double Click icon's flaws

Under Windows, you can open the Python file by double-click the icon, but this is easy to show. First, the file output window will disappear immediately after running, if you want it to be open, add the RAW_INPUT () statement at the end of the file, and you must know that the window will disappear when the program has an error. If you want to see the error message, use other methods to run files, for example, in the command line, IDLE.

5. Import package is only the first work

You have to run a file, you might use import, but import only works for the first time, when you want to overwrite a file, use Reload (Module). Otherwise, you will return your first introduced package (file). 6. Blank line problem under interactive prompt

The blank line and comments in Module are always ignored under interactive prompts. But when you type a command at an interactive prompt, the blank line marks the end of a composite statement. In other words, blank line tells the interpreter that you have completed a complex sentence. So, don't type the Enter key when you haven't completed a complex statement.

I will see Yu Minhong's red book, first come here, turn it up, and it's bad.

转载请注明原文地址:https://www.9cbs.com/read-22326.html

New Post(0)