wierd error after if or while

Aahz Maruch aahz at netcom.com
Tue May 9 08:57:15 EDT 2000

In article <8f90uq$u4v$1 at nnrp1.deja.com>,  <nick_knight at my-deja.com> wrote:
>I am a newbie - in fact I just downloaded it today, and so far it looks
>like a very useful language. The only problem is I seem to be doing
>something stupid. If I run the folloing bit of code
>x = 4
>if x==4:
>print "hello"
>I get the following error message
>  File "<stdin>", line 2
>    print "hello",
>        ^

First of all, next time please include the entire error message.  In
this case, I know you received a syntax error, but that might not be so
obvious next time.

The problem is that Python uses whitespace to indicate that statements
belong in a block.  Your "if" starts a new block, so the "print" needs
to be indented, like this:

if x==4:
    print "hello"
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"It's not because my mind is made up that I don't want you to confuse me
with any more facts.  It's because my mind isn't made up.  I already have 
more facts than I can cope with.  So SHUT UP, do you hear me?  SHUT UP!"  
_The Shockwave Rider_, 1975

More information about the Python-list mailing list