From 9be5bbcce760e7d8ae53b0ad58c7ebb44e4e1f76 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Fri, 15 May 2009 16:17:43 -0400 Subject: [PATCH] typo --- your-first-python-program.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/your-first-python-program.html b/your-first-python-program.html index f69c932..53f56f5 100644 --- a/your-first-python-program.html +++ b/your-first-python-program.html @@ -236,7 +236,7 @@ SyntaxError: non-keyword arg after keyword arg
  • Code blocks are defined by their indentation. By "code block," I mean functions, if statements, for loops, while loops, and so forth. Indenting starts a block and unindenting ends it. There are no explicit braces, brackets, or keywords. This means that whitespace is significant, and must be consistent. In this example, the function code is indented four spaces. It doesn’t need to be four spaces, it just needs to be consistent. The first line that is not indented marks the end of the function.
  • In Python, an if statement is followed by a code block. If the if expression evaluates to true, the indented block is executed, otherwise it falls to the else block (if any). (Note the lack of parentheses around the expression.)
  • This line is inside the if code block. This raise statement will raise an exception (of type ValueError), but only if size < 0. -
  • This is not the end of the function. Completely blank lines don’t count. They help more the code more readable, but they don’t count as code block delimiters. The function continues on the next line. +
  • This is not the end of the function. Completely blank lines don’t count. They can make the code more readable, but they don’t count as code block delimiters. The function continues on the next line.
  • The for loop also marks the start of a code block. Code blocks can contain multiple lines, as long as they are all indented the same amount. This for loop has three lines of code in it. There is no other special syntax for multi-line code blocks. Just indent and get on with your life.

    After some initial protests and several snide analogies to Fortran, you will make peace with this and start seeing its benefits. One major benefit is that all Python programs look similar, since indentation is a language requirement and not a matter of style. This makes it easier to read and understand other people’s Python code.