First commands
Python is an
interpreted language, meaning it executes code line by line, unlike
Pascal or C/C++, which require a compiler to generate an executable file. The
console allows us to
execute one Python command at a time and immediately see the effect. The current position is indicated by the
three characters "
>>" and the
cursor ("|").
The simplest commands display a text or the result of arithmetic operations.
EXERCISE 1
|
check_circle_outline
|
Enter the command
print("Hello, Python!") and then press
the
Enter key.
Pay attention to the quotation marks!
Congratulations! print is a built-in function that
displays data provided as arguments, which are written within parentheses following its name!
In this case, there was only one: a text string enclosed in quotation marks.
error_outline
|
Warning! Something is definitely wrong...
|
Python indicates the error in the console.
|
EXERCISE 2
|
check_circle_outline
|
Arithmetic calculations? Nothing simpler! We can write them directly in the Python console.
Enter the exactly command
2+3*5-1 and then press the
Enter key.
Great!
As you can see, Python "knows" the operator precedence, and the result is 16.
Play around a bit with addition (+), subtraction (-), multiplication (*), and division (/) for now.
Is the console sufficient?
The working mode directly in the console (called the "
Python Interactive Console") is interesting
and different from what you might be used to. However, we still need programs that contain multiple lines of code,
written and executed together to obtain results from calculations or elaborate algorithms.
The console is useful when we need quick access to Python or want to test certain commands.
On the next page, we will write our first programs!
You have completed both exercises! Let's move on to the next page!
Solve both exercises before proceeding. Each contains important feedback!