How To Use Console Python

The Python programming language can also be used in interactive line mode

What is Python's interactive mode? Interactive mode is an alternative to editing source code on file. It is particularly useful for me to test single features of a program during the debugging phase. Functions and commands are executed directly from the shell without a script.

How python works in interactive mode

I open the interactive python mode ( not IDLE ) to display the shell or the command line.

come aprire la riga comando di python

The shell opens with the python interpreter prompt.

Now I can type in the instructions to be executed. One after the other.

il prompt dell'interprete python

Every time I execute an instruction, python saves the result in memory.

Thus, the output of an instruction changes the result of subsequent statements as in a real program.

A practical example

On the python command line, I initialize the variable A and I assign it the numerical value A = 10.

inizializzazione della variabile in Python da riga comando ( modalità interattiva )

The interpreter executes the instruction. After execution, the command line prompt reappears.

Now, I type the PRINT (A) statement to display the contents of the variable.

come funziona python in modalità interattiva

The interpreter returns me the value 10 in output.

What happened?

The explanation is very simple. Python has stored in memory the assignment of the value 10 to the variable A (first instruction).

il funzionamento di python da riga comando (shell)

When I asked to display the contents of variable A, the interpreter simply read and displayed the value of the variable in memory.

For this reason, the python language is considered an interactive language.

 
 

Please feel free to point out any errors or typos, or share your suggestions to enhance these notes

FacebookTwitterLinkedinLinkedin
knowledge base

Python