The content of this article is to write your
The first Python programIn
Python's interactive command-line write program, the advantage is that you can get the result, the disadvantage is unable to save, the next time you want to run, you have to knock again.
So, when actually developing, we always use a Python text editor to write code, write it down, save it as a file, so that the program can run repeatedly.
Now, we'll write the last ' Hello, World ' program with a text editor and save it.
So here's the question: where is the text editor strong?
Two text editors recommended:
One is Sublime Text, free to use, but no charge will pop up the prompt box:
One is notepad++, free to use, with Chinese interface:
Note that you can use whichever, but never use Notepad with Word and windows. Word does not save plain text files, and Notepad will be smart to add a few special characters (UTF-8 BOM) to the beginning of the file, resulting in an inexplicable error in the program running.
Once the text editor is installed, we can write our first Python program :
Print (' Hello, World ')
Note that there are no spaces in front of print . Then, select a directory, such as C:\work, save the file as hello.py, you can open the Command Line window, the current directory to switch to the hello.py directory, you can run the program:
C:\work>python Hello.pyhello, World
It can also be saved as a different name, such as first.py, but must end with a. py. In addition, the file name can only be a combination of English letters, numbers, and underscores.
If the file is not hello.py in the current directory, running Python hello.py will cause an error:
C:\users\ieuser>python hello.pypython:can ' t open file ' hello.py ': [Errno 2] No such file or directory
Above, it explains how to write your first Python program.