Program Structure

A Python program is a sequence of statements. A statement is a line of code that performs some action. For example, the following program prints the string "Hello, World!" to the console:

print("Hello, World!")

Programs are executed from top to bottom. The first statement in a program is executed first, followed by the second statement, and so on. In the above example, the print statement is the only statement in the program, so it is executed first.

Python programs are whitespace sensitive, meaning that the indentation of a line of code is important. The indentation of a like is the number of spaces at the beginning of the line. The number of spaces used for indentation must be the same across all lines of code, we choose to use 4 spaces for indentation. This means that if we talk about an indentation of 2, we mean 8 spaces.

Programs are structured using indentation. Indentation is the number of spaces at the beginning of a line. Indentation is used during control flow statements, such as if statements and for loops. We will cover control flow in a later section.

An example of indentation is shown below:

if True:
    print("Hello, World!")