Question: The documentation states:  A Python program is constructed from code blocks. A block is a piece of Python program text that is executed as a unit. The following are blocks: a module, a function body, and a class definition.  This seems to imply, contrary to what I had thought, that an indented piece of code, such as the body of an if-statement or a for-loop is not a block. Am I reading this correctly? What does it mean to be executed as a unit (e.g. why wouldn't a for-loop fit this definition)? What would you call an indented piece of code if not a block?

Answer:  This seems to imply, contrary to what I had thought, that an indented piece of code, such as the body of an if-statement or a for-loop is not a block.  Indeed, at least in the technical context of the Python language reference, what we would normally call an "indented block" is not a "block". It's not unusual in technical specifications that words are given specific contextual meanings which are different to their usual meanings, and unfortunately sometimes this happens when the usual meaning is also a technical one.  What would you call an indented piece of code if not a block?  The Python language reference calls it a suite. But I think most Python programmers would rather call it a block, unless they were proposing an edit to the language reference.  What does it mean to be executed as a unit (e.g. why wouldn't a for-loop fit this definition)?  This means that a "block" (in the strict technical sense of the Python language reference) corresponds with a code object, is executed in a stack frame, and has its own lexical scope. A for loop does not meet this definition because it does not have its own code object, stack frame or lexical scope; its bytecode is part of the containing block's code object, it is executed in the containing block's stack frame, and it has the containing block's lexical scope. Practically, all this means is that variables declared inside a for loop (or any other suite) are still in scope after the suite has executed, until the end of the "block".   I really don't like variables in compound statements not being local to the statement... Why wouldn't Python allow me to have a small scope for variables?  C-like languages have "block scope" (where the word "block" here means a sequence of statements delimited by a pair of braces), but they also allow you to declare variables without assigning to them yet, so you can declare them in the correct scope even if the assignment will occur in a different scope. For example, the following is totally fine in C, Java or similar languages: int x; if(condition) { x = 5; } else { x = 7; }  But Python is a dynamic language in which you don't need to declare variables before you assign to them, so the equivalent Python code would be: if condition: x = 5 else: x = 7  If Python's "suites" had their own lexical scopes then this pattern wouldn't work; x would be local to the if and else scopes and would not be in scope afterwards. To get the same behaviour as the C code, you'd have to write a dummy x = None assignment before the if statement in order to declare x in the correct scope (and, perhaps, nonlocal x so that the assignments in the if and else suites would not instead declare new local variables in their own scopes). This would be silly and with very little upside, so it makes sense that Python is not designed that way.