Primary and secondary prompt in Python

The ">>>" sign seen on the Python’s interactive shell is called a prompt. Python’s interactive shell, which appears after firing command “python3” (if we are working on python version 3) on the terminal, has two such prompts.

">>>" - Primary prompt
"..." - Secondary prompt

When we fire command ‘python3’ on terminal, >>> sign is immediately seen on screen. This “>>>” sign is nothing but the primary prompt.

Whenever cursor is blinking next to a primary prompt on terminal, it means interpreter will take ‘one and only one’ instruction and execute it immediately if the instruction is found valid

Example:

python3-primary-prompt



Firstly interpreter will immediately execute a = 10 while doing so it will create an integer object, store 10 inside that integer object and bind that particular object to a variable called ‘a’

After executing the first instruction, the interpreter moves to the next instruction b = 20 and immediately executes it, just like it executed a = 10, and finally prints the output.

However, once we get to see a secondary prompt that is “…”, it means that now we have entered a block, that block can be if block, else block, elif block, while, for or any other block. Once inside a block, ‘…’ signifies, all the instructions of the block, entered in front of “…” will be executed by interpreter together “as a series of instructions”.

Example:

python-secondary-prompt

Hereafter writing if statement, naturally interpreter enters in if block and starts showing “…”(secondary prompt) to indicate that now the interpreter is ready to take ‘series of instructions’, which will be executed altogether as a group if, ‘if’ statement is found valid.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.