What is the meaning of the >>> prompt in Python?

Asked 1 years ago, Updated 1 years ago, 336 views

In Python

>>>

What is the meaning of the above prompt?

In a textbook

>>12+22
34

It was written like this, but I think this is the same for the following cases.What's the difference?

12+22
34

python command-prompt

2022-12-20 23:29

2 Answers

The Python documentation contains a description.
2.Using the Python Interpreter
2.1.2.Interactive Mode

If the interpreter is reading instructions from a terminal (tty) or command prompt, the interpreter is said to be operating in interactive mode. In this mode, the interpreter prompts the user to enter the command by displaying a primary prompt.The primary prompt is usually three 大large symbols 」 (>>>).In the continuous line, the interpreter displays a secondary prompt.The secondary prompt is three dots (...) by default. The interpreter prints a launch message that begins with the version number and copyright notice before issuing the first prompt:

According to the above description, >>> is a combination of ... to indicate the state at which the command was entered.

>>> is the initial input state, and nothing was entered before that, and it is the basic state that requires no indentation or parenthesis/quotation to be closed.

If the prompt changes to ..., indentation is required in the if or for statements, or the statements and expressions are not completed in the middle of the input.

By the way, the expression where you enter the prompt seems a little vague, and it can also be taken as if the person you are manipulating needs to key in >>.

The Python interpreter is doing the prompt.
The reason >>> is written in textbooks and other materials is probably because the Python interpreter directly reflects what the operator is seeing to prompt (that's what the word prompt means).


2022-12-21 10:12

I think >>> indicates that it is running in interactive mode.
It's not the code of the program.


2022-12-21 22:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.