Command line mode
Select "Command Prompt" in the Windows start menu to enter the command line mode. Its prompt is similar to C:\
Python interactive mode
Knock on the command python in the command line mode, and you will see a bunch of text output similar to the following, and then enter the Python interactive mode, its prompt is,
Enter exit() in the Python interactive mode and press Enter to exit the Python interactive mode and return to the command line mode:
**Distinguish between command line mode and Python interactive mode: **
In the command line mode, you can execute python to enter the Python interactive environment, or execute python hello.py to run a .py file
Executing a .py file can only be executed in command line mode. If you type a command python hello.py, you will see an error: The error message No such file or directory means that this hello.py cannot be found in the current directory. You must first switch the current directory to the directory where hello.py is located. carried out
There is a difference between running .py files in command line mode and running Python code directly in the Python interactive environment. The Python interactive environment will automatically print the results of each line of Python code, but it will not be possible to run the Python code directly.
In the Python interactive environment:
100+200+300600
In command line mode:
print(100+200+300)
C:\work pythoncalc.py
600
The code in the Python interactive mode is to input one line and execute one line, while running the .py file directly in the command line mode executes all the codes in the file at once. It can be seen that the Python interactive mode is mainly used for debugging Python code, and it is also convenient for beginners to learn. It is not an environment for officially running Python code!
summary:
In the Python interactive mode, you can directly enter the code, then execute it, and get the result immediately.
In the command line mode, you can run the .py file directly.
Knowledge point expansion:
Command line mode and python interactive mode
Line python hello.py to run a .py file.
In the Python interactive environment, you can only enter Python code and execute it immediately.
The Python interactive environment will automatically print the results of each line of Python code, but it will not be possible to run the Python code directly.
The above is the detailed content of the basic knowledge points of the python interactive mode. For more information about the python interactive mode, please pay attention to other related articles on ZaLou.Cn!
Recommended Posts