[Tutor] python Error:IndentationError: expected an indented block
Kent Johnson
kent37 at tds.net
Tue Jan 9 14:18:44 CET 2007
ziok wrote:
> 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)
>>>> z=['ze','se']
>>>> 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:
>>> z=['ze','se']
>>> for s in z:
... if s=='ze':
... print 'found ze'
... else:
... print 'not ze'
Kent
More information about the Tutor
mailing list