lettura simple

How to use Python console

In this online lesson I'll explain how to use Python console (shell o terminal). It is one of the first steps of programming in Python.

What is Python shell? The shell is a command line where you can type Python commands. When you type a command and hit enter, the command is executed by the language interpreter. The result is displayed in real time and saved in the computer's volatile memory (RAM).

I'll give you a practical example.

Open the Python terminal.

If you are using a PC Windows select Python command line.

Python command line

The Python terminal displays a >>> prompt with a blinking cursor.

the Python shell

Type 2+2 on the command line and hit enter.

Python shows the result on the next line like a simple calculator.

>>> 2+2
4

Fin qui nulla di nuovo.

Now type the command a = 5 and give enter.

>>> a=5

Python interpreter stores the value 5 in the variable a.

Then type the command b = 2 and enter.

>>> b=2

Python interpreter stores the value 2 in the variable b.

At this point, type a + b and hit enter.

>>> a+b
7

Python interpreter remembers that you have assigned values to variables a=5 e b=2.

Then, it adds the values a + b and returns the result of the addition 5+2=7.

What is the Python shell for?

It allows you to enter commands line by line and see the result in real time.

It is useful for making some quick calculations in sequence or for verifying the correct functioning of an algorithm.

Tip. Press the up and down arrow keys on your PC keyboard to scroll through the commands you typed earlier on the command line. Previous commands remain in memory in the current session but are not saved. When you close the terminal they are lost. If you want to save them, you need to write them to a text file and create a python script.

If you like this lesson from Nigiara's Python online course, keep following us.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin