Today from the title of the note, you may be confused, what "initial steps"? This title is the title of the third chapter of the Concise Python tutorial, which I will explain to you.
The "first step" is mainly about what you've just learned, practiced python, and how to execute Python code.
First, use the editor with a prompt
The editor with a prompt is the terminal used by the Linux system and the command prompt used in the Windows system.
At the Linux terminal shell prompt, enter Python, start the Pthon interpreter, enter print ' Hello world ' and press ENTER (return), and you can see the returned value, as shown in the following figure:
Note:>>> is a python prompt, press CTRL + D or enter exit () to exit the interpreter.
Just open the cmd command prompt on the Windows system, enter Python, start the Python interpreter, the same way as the terminal in Linux, as shown in the following figure:
Note: Press CTRL + Z or exit () to exit the interpreter.
Second, choose a suitable editor
Picking an editor is very important, a good editor can improve the efficiency of writing code can make you write code more relaxed and comfortable.
The basic requirement for the editor is that the syntax is highlighted, and using this feature, your Python program will be labeled in a different color, allowing you to better see how to clear your program.
Another basic requirement is the indentation function of the code, "indentation means that the lines of code are reserved before the space, is generally the TAB key for a indent unit, but if your editor does not support, you need to look at the space, is not very troublesome.
Linux operating system you can choose to use Vim,vim is the operating system's own editor, support syntax highlighting and indentation function. Of course, you can also use Emacs, an old and powerful editor.
Windows operating system is more: sublime, syntax highlights, indentation, automatic identification of words, the wrong line can be, I personally prefer this.
There are editplus, basic requirements are also supported, with the feeling is not bad.
Iii. use of source files
Every time you learn a new programming language, the first program you write is usually the "Hello World" program. When you run the Hello World program, the only thing they do is output "Hello World".
Start the editor you selected, enter the following code, and save them as helloworld.py
#/usr/bin/env python
#Filename: helloworld.py
Print "Hello world."
To run this program, open the shell terminal and enter the Python helloworld.py, you run your first Python program successfully.
Note: Python is strictly case-sensitive, and "P" in print is lowercase, not uppercase.
Of course, you can also make your program an executable python program that executes:
chmod +x helloworld.py # # #赋予可执行权限
./helloworld.py #执行程序