[Tutor] Indentation woes in elif statement

Joel Goldstick joel.goldstick at gmail.com
Wed Aug 11 14:13:55 CEST 2010

On Tue, Aug 10, 2010 at 9:11 PM, rara avis <fried.sigmund at gmail.com> wrote:

> Hi: I am trying to teach myself Python, and am stuck at the indentation
> with the elif statement.
> This is what I am trying to type:
> x=3
> if x==0:
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
x = 3
if x == 0:
  print 'x == 0'
elif x != 0:
  print 'x != 0'

x != 0
The block of code under 'if x...' is indented.  Most people use 4 spaces.
You can use any number of spaces, but you need to be consistant
The elif indentation must match its matching if statement.  In this case
neither are indented
The block which executes under the elif is indented to the same level as
that under the original if

Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100811/76181bd7/attachment.html>

More information about the Tutor mailing list