1. Using the Python interpreter:
1. When installing python, there will usually be an interactive interpreter, where we can directly write and run
#2. But if we turn it off, the code we just wrote will be lost. At this point, we create a new text document, write print 'hello world', and then rewrite the file name as: hello.py. Note that the suffix is py, and your computer must display the suffix to see it. Then, we open the interpreter and open the py we just wrote through file->open
3. After opening, the following interface will be displayed, which is the code we just wrote
4. At this time, you can click Run->run module, or press F5 directly to run the code, as shown in the figure below, the operation is successful and the result is printed
2. Run through the command line
As shown in the figure below, there is a hello.py file
We directly enter cmd in the file address bar above and hit Enter
You can see that it will be directly located in the corresponding directory
We enter python hello.py, we can run the program
or we can run hello.py directly
3. Double-click to run:
You can directly double-click to run, but the window will flash by. What should I do?
Add the following code:
raw_input('press
At this time, we double-click the program directly and find that the cmd box has not disappeared. The interface will disappear only after you press the Enter key
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to run code program in python. For more information, please follow other related articles on the PHP Chinese website!