The following is a valuable suggestion. For those programming learners who have never learned programming or are not computer professional, the Python program is one of the best choices, it is recommended that beginners learn programming from Python first.
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 ). 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. Now let's start programming again. 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, who proposed the "Hello World" program, said, "It is a traditional spell of the god of programming and can help you better learn languages ."
To run this program, open the shellLinux terminal or DOS prompt), and then type the python helloworld. py command. If you are using IDLE, use menu Edit-> Run Script or use keyboard shortcuts Ctrl-F5. The output is as follows.
- $ python helloworld.py
- Hello World
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 and 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.
How it works: let's think about the first two lines of the 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.
- How to embed Python into C ++ applications?
- In-depth discussion of Ruby and Python syntax comparison
- Introduction to Python
- Python Learning Experience: version, IDE selection and encoding solution
- Analysis of Python GIL and thread security