Examining syntax rules

There are nine fundamental syntax rules in section 2.1 of the Python Language Reference. We'll summarize those rules here:

  1. There are two species of statements: simple and compound. Simple statements must be complete on a single logical line. A compound statement starts with a single logical line and must contain indented statements. The initial clause of a compound statement ends with a : character. It's possible, using rules 5 and 6, to join a number of physical lines together to create a single logical line.
    • Here's a typical simple statement, complete in a single logical line:
      from decimal import Decimal
    • Here's a typical compound statement with a nested simple statement, spread across two logical lines:
      if a > b: print(a, "is ...

Get Python Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.