Guide Python Beginner

4.3 Statements

Simple statements vs compound statements in Python, placing multiple statements on one line, and splitting a long statement across multiple lines.

2 min read
flowchart LR subgraph Header["Compound statement header"] K["if"] --> I["age"] --> O[">="] --> L["18"] --> C[":"] end Header --> Body["print(\"Adult\")\n(indented block — the body)"]

The parts that make up a compound statement: keyword, identifier, operator, literal, and the colon that starts the block.

Simple Statements

What Is It?

A statement that fits entirely on one logical line and doesn’t introduce a new block — assignments, function calls, imports, return, etc.

Why Is It Used?

It’s the basic unit of action in Python; most lines of real code are simple statements.

x = 5           # assignment
print(x)        # function call
import os       # import
return x        # return (inside a function)

Compound Statements

What Is It?

A statement that contains other statements as an indented block — if, for, while, def, class, try.

Why Is It Used?

This is how Python expresses control flow and structure; the header line ends in a colon, and everything indented beneath it is the block.

if x > 0:
    print("positive")   # this indented block is part of the if statement

Multiple Statements

What Is It?

Placing more than one simple statement on a single physical line, separated by semicolons.

Why Is It Rarely Used?

PEP 8 (see 4.16 Coding Standards) discourages this because it hurts readability — mentioned here for completeness, not as a recommended style.

>>> a = 1; b = 2; print(a, b)
1 2

Line Continuation

What Is It?

Splitting one logical statement across multiple physical lines, either explicitly with a trailing backslash or implicitly inside brackets.

Why Is It Used?

It keeps long expressions readable instead of one very long line.

How Is It Used?

See 4.15 Multiple Statements & Line Continuation for the full comparison of both styles.

total = 1 + \
        2 + \
        3
>>> total
6

Quick Interview Answer

“A simple statement fits on one line and does one thing — an assignment, a function call, an import. A compound statement has a colon-terminated header and an indented block beneath it — if, for, def, class. You can technically cram multiple simple statements onto one line with semicolons, but PEP 8 discourages it.”

Common Mistakes

  • Forgetting the colon at the end of a compound statement’s header line — the single most common beginner SyntaxError.
  • Overusing semicolons to combine simple statements, which hurts readability without any real performance benefit.

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form