[Tutor] python Error:IndentationError: expected an indented block
kent37 at tds.net
Tue Jan 9 14:18:44 CET 2007
> hi ..
> i'm learning python .i have a book with examples. i did the examples for
> "if" and have the same errors...
> here is the simple code(two of them)
>>>> for s in z:
> ... if s=='ze':
> File "<stdin>", line 2
> if s=='ze':
> IndentationError: expected an indented block
Python uses indentation to define blocks. For example, to show which
statements are controlled by a for or if statement, the controlled
statements are indented. Your book should talk about this.
So when typing these examples you need to indent the lines after the
for, if or while. The indentation can be any consistent white space.
Four spaces is a very common indent. When typing at the interactive
prompt I usually use two spaces just because it's easier to type.
Your code should look something like this:
>>> for s in z:
... if s=='ze':
... print 'found ze'
... print 'not ze'
More information about the Tutor