How to select a Python editor correctly?

Source: Internet
Author: User

After studying the Python editor for a long time, I would like to share with you that you will certainly have a lot of gains after reading this article. I hope this article will teach you more things and learn about the Python editor, you may encounter a Python editor problem. Here we will introduce the solution to the Python editor problem and share it with you here.

You can select an editor just like you can select a car you will buy. A good editor will help you easily write Python programs, make your programming journey more comfortable, and help you reach your destination more quickly and securely (to achieve your goal ).

One of the basic requirements of the editor is the syntax brightening function. With this function, different parts of your Python program are marked with different colors, so that you can better understand your program, to visualize its operation. If you are using Windows, we recommend that you use IDLE. IDLE has the syntax brightening function and many other functions, such as allowing you to run your program in IDLE.

Note: Do not use Notepad-it is a bad choice, because it does not have the syntax brightening function, and more importantly, it does not support text indentation. We will see that text indentation is extremely important to us. A good editor, such as IDLE (and VIM), will automatically help you do these tasks.

If you use Linux/FreeBSD, you have many options. If you are an experienced programmer, you must be using VIM or Emacs. Undoubtedly, they are two of the most powerful editors. You will benefit from using them to write your Python program. I personally use VIM to write most of my programs.

If you are a beginner in programming, you can use Kate, which is also one of my favorite editors. As long as you are willing to spend time learning to use VIM or Emacs, I strongly recommend that you learn either of them, because they are extremely helpful in the long run.

If you want to find other available editors, you can take a look at the detailed Python editor list and make your choice. You can also use Python IDE (integrated development environment ). For more information, see the Python-supported IDE list. Once you write a large Python program, the IDE is really useful.

Once again, select an appropriate editor that makes it more interesting and convenient to write Python programs. Now let's start programming with the source file. When you learn a new programming language, the first program you write and run is usually a "Hello World" program, which has become a tradition.

When you run the "Hello World" program, all it does is say "Hello World ". As Simon Cozens [1], who proposed the "Hello World" program, said: "It is a traditional spell of the god of programming and can help you better learn languages ." If the output you get is the same as the one shown above, congratulations! -- You have successfully run your first Python program. In case you get an error, make sure that the program you typed is correct.

Then run the program. Note that Python is case sensitive, that is, print is different from Print-note that the first is lower case p and the other is upper case P. In addition, make sure there are no spaces or tabs before the start character of each line-we will discuss why this is important later. Let's think about the first two lines of this program. They are called annotations-any content on the right of the # symbol is annotated. Annotations are mainly used as notes provided to program readers.

Python should have at least the special form of comments in the first line. It is called an organizational line. The first two characters of the source file are #!, Followed by a program. This line tells your Linux/Unix system which interpreter should be run when you execute your program. This will be explained in detail in the next section.

Note: You can always specify the interpreter directly on the command line to run your program on any platform. Just like the python helloworld. py command. Rational use of comments in your program to explain some important details-this will help readers of your program easily understand what the program is doing. Remember, this reader may be you six months later!

After the annotation, a Python statement is used to print the text "Hello World ". Print is actually an operator, and "Hello World" is called a string-don't worry, we will explain these terms in detail later.

If you want to get help for operators such as print, you need to correctly set the PYTHONDOCS environment variable. This can be easily done using the env command in Linux/Unix.

 
 
  1. $ env PYTHONDOCS=/usr/share/doc/python-docs-2.3.4/html/ python  
  2. Python 2.3.4 (#1, Oct 26 2004, 16:42:40)  
  3. [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2  
  4. Type "help", "copyright", "credits" or "license" for more information.  
  5. >>> help('print')  

You should note that I use quotation marks on "print", so that Python can understand that I want to get help on "print" instead of asking for something to print. Note that I am using a location in Fedora Core 3 Linux -- it may be different in different releases and versions.

  1. Introduction to Python system files
  2. How to correctly use Python Functions
  3. Detailed introduction and analysis of Python build tools
  4. Advantages of Python in PythonAndroid
  5. How to Use the Python module to parse the configuration file?

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.