After installing Python, enter "python" on the command line, if successful, you will get a window similar to the following:
As you can see, there are 3 symbols () at the end. Called the Python command prompt (prompt), Python is waiting for you to enter the code. You can now enter a line of Python code, and Python will execute the code. This mode is called Python interactive mode (interactive mode), because Python is waiting for you to enter code and then execute it.
For example, you can enter an expression and let Python calculate it. For example, to calculate 1+1, you can enter 1+1 at the command prompt, and then press enter:
1+1
After pressing enter, Python will output the calculation result, here is 2.
To exit the Python interactive mode, you can enter exit() at the Python command prompt:
exit()
You can also enter quit():
quit()
Knowledge point expansion:
**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 python calc.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!
So far, this article on how python enters interactive mode is introduced. For more related methods for python to enter interactive mode, please search for ZaLou.Cn's previous articles or continue to browse related articles below. Hope you will support ZaLou more in the future. Cn!
Recommended Posts