Statements
Learn all about Statements in this comprehensive tutorial.
- •A **computer program** is a list of "instructions" to be "executed" by a computer.
- •Most Python programs contain many statements.
- •Semicolons are optional in Python.
Statements
A computer program is a list of "instructions" to be "executed" by a computer.
In a programming language, these programming instructions are called statements.
The following statement prints the text "Python is fun!" to the screen:
In Python, a statement usually ends when the line ends. You do not need to use a semicolon (;) like in many other programming languages (for example, Java or C).
Many Statements
Most Python programs contain many statements.
The statements are executed one by one, in the same order as they are written:
From the example above, we have three statements:
- print("Hello World!")
- print("Have a good day.")
- print("Learning Python is fun!")
The first statement is executed first (print "Hello World!"). Then the second statement is executed (print "Have a good day."). And at last, the third statement is executed (print "Learning Python is fun!").
Semicolons (Optional, Rarely Used)
Semicolons are optional in Python. You can write multiple statements on one line by separating them with ; but this is rarely used because it makes it hard to read:
However, if you put two statements on the same line without a separator (newline or ;), Python will give an error:
Module quiz
2 questionsWhich of the following is true about Statements?
What is the most common pitfall when working with Statements?
Answer all questions to submit.