What the Python designers realized is that braces or begin/end
keywords are mostly noise to human programmers. They generally recognize the structure of code by its layout. For instance, if you were to write the C code:
if (condition)
x = y;
w = z;
a human would often not notice that the braces are missing, and assume that both assignments are controlled by the condition. Writing code like this is a common error, especially when you start with a block that has just one statement (so the braces are optional and were omitted), and forget to add braces when a second statement is added. (See Why is it considered a bad practice to omit curly braces?).
Conversely, if you write
if (condition) {
x = y;
w = z;
}
it looks like w = z;
is not part of the conditional.
Braces mainly exist for the benefit of software that processes code (compilers, editors, IDEs), they make it easier for them to detect groups of code. The Python designers decided to mirror the way humans read code in their parser, rather than forcing humans to adapt to the computer's needs.
Braces allow for more flexible code layout, but in practice it's usually condiered wrong to take advantage of this. Writing code like
while (something) { statement1; statement2;
statement3; }
is less readable than
while something:
statement1
statement2
statement3
Python does allow some flexibility: You can separate statements on the same line with ;
, and put the contents of a conditional on the same line after the :
. But writing like this is not considered Pythonic, and should be used only in very special circumstances (this blog post describes those cases).
There's always some adjustment necessary when you're learning a new programming language and you're accustomed to the patterns of the languages you previously used (many programmers have refused to learn Lisp, because of its Lots of Irritating, Stupid Parentheses). But give it a little time and you'll get used to it.