bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Python/Foundations
Python•Foundations

Python Statements

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Python Statements?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___("Python is fun!")
3Order

Put the learning moves in the order that makes the concept easiest to apply.

In a programming language, these programming instructions are called statements .
A computer program is a list of "instructions" to be "executed" by a computer.
Semicolons (Optional, Rarely Used)

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:

Example

print("Python is fun!")

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:

Example

print("Hello World!")
print("Have a good day.")
print("Learning Python is fun!")

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:

Example

print("Hello"); print("How are
you?"); print("Bye bye!")

However, if you put two statements on the same line without a separator (newline or ; ), Python will give an error:

Example

print("Python is fun!") print("Really!")

Expected output

SyntaxError: invalid syntax

Best practice: Put each statement on its own line so your code is easy to understand.

Previous

Python Syntax

Next

Python Output / Print