Skip to main content

Statements

A program is simply a list of instructions for a computer to carry out. Each of those instructions is known as a statement.

A Python statement normally stops where its line stops, so there is no need for the semicolon (;) that many other languages require.

Example

Prompt
Print "Python is fun!" to the screen.
Output: complete Python program

Many Statements

A typical Python program is made of many statements. Python runs them one at a time, from first to last, following the order you wrote them in.

Example

Prompt
Print three lines: "Hello World!", "Have a good day.", and "Learning Python is fun!" using three separate print statements.
Output: complete Python program

Semicolons (Optional, Rarely Used)

Python doesn't require semicolons. You may use ; to place several statements on one line, but few people do, since the result is hard to read.

Note: Two statements on one line need a separator (a newline or ;) between them, or Python reports an error. The recommended habit is one statement per line.

Semicolons

Prompt
Print three messages on a single line separated by semicolons: "Hello", "How are you?", and "Bye bye!".
Output: complete Python program

No separator error

Here the separator between the two statements is missing, which causes an error:

Prompt
Demonstrate a syntax error by putting two print statements on the same line without a semicolon separator.
Output: complete Python program