Register to get access to free programming courses with interactive exercises

Instructions Python Basics

Instructions

When we're making a dish, we follow the recipe carefully. Otherwise, the food won't turn out as expected. The same rule applies to programming.

We want to see the expected result onscreen, so we should give the computer clear, step-by-step directions. We can do it using instructions. An instruction is a command to the computer, a unit of execution. In this case, Python code is a set of instructions. We can present it as a step-by-step recipe.

We run the Python code using an interpreter, a program that executes instructions strictly one at a time. Like the steps in a recipe, the instructions for the interpreter are written in order and separated by jumping to the following line.

Developers must understand the order of operations in the code and be able to mentally break the program into independent parts that are convenient for analysis.

Let's look at an example of some code with two instructions. When it's started, two sentences are displayed sequentially on the screen:

print('Mother of Dragons.')
print('Dracarys!')
# => Mother of Dragons.
# => Dracarys!

We said above that instructions are separated from each other by a line break. But there is another way: you can separate them with a semicolon:

print('Mother of Dragons.'); print('Drakarys!')

There is no technical difference between the first and second versions. The interpreter will understand the instructions the same way, but it is physically inconvenient to read the second version.

It is better to place the instructions under each other. It makes it easier for colleagues to read your code, maintain it, and make changes.


Recommended materials

  1. A little about interpreters

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

Bookmate
Health Samurai
Dualboot
ABBYY