How does python enter interactive mode

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

How does python enter interactive mode
How does Python output integers
How does python output backslashes
How does python update packages
How does python perform matrix operations
How does Python list update value
How does python change the environment
How does python call java classes
How does python import dependency packages
How does Python generate xml files
How does python determine prime numbers
How does python improve the calculation speed
How does python call its own function
How does Python handle the json module
How does python distinguish return and yield
How to enter python triple quotation marks
How to enter python through the command line
How does Python store data to json files
How does python call the key of a dictionary
How does python get input examples from the keyboard
Python single instance mode
How python was invented
How does python handle the program cannot be opened
How does python judge the module installation is complete
How Python parses XML
How long does it take to learn python by myself?
How to comment python code
How Python converts string case
How to learn python quickly
How to uninstall python plugin
Does Python support multiple inheritance?
How Python implements FTP function
How to understand python objects
How to use python tuples
Explain how python references package package