Code block syntax

There are two simple syntax rules to remember about code blocks:

• The code on the first line of a code block always ends with a colon (: ).

• The code underneath the first line of a code block is indented.

Python programmers almost always use four spaces for the first level of indentation, eight spaces for the next level (a code block nested inside another code block), and so on.

The indentation must be the same for every line of a block. You get an indentationError message if you use, for example, four spaces on one line of a block and three spaces on another line in the same block.

Was this article helpful?

0 0

Post a comment