[Tutor] trouble with indents
simplebob at gmail.com
Mon May 28 20:44:48 CEST 2007
I would recomend you take a look at Alan Gauld's tutor. That is what got me
started and I was able to catch on fairly quick even with little to no
On 5/28/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "adam urbas" <adamurbas at hotmail.com> wrote in
> > I'm not sure when to indent. I understand that it has to be done.
> Ok, But you need to understand *why* it has to be done.
> To do that you need to understand the basic constructs
> of programming: sequences, branches, loops and modules.
> (these are described in the concepts section of my tutorial)
> Basically each construct is defined by indenting in python.
> Thus if you have a loop in your code the set of instructions
> to be repeated is indented. This makes it visually clear what
> gets repeated. More importantly it tells the Python interpreter
> what it should repeat!
> Thus, simplistically, you need to indent anything following
> a colon.
> That is after a branch instruction: if/elif/else
> or a loop: for/while
> or a function(module) definition: def
> or inside a class: class
> The next trick is to determine when to stop indenting and
> that's actually harder to describe! Its basically when you
> want Python to stop treating your code as special - eg no
> longer part of the code to be repeated in a loop.
> > I need somewhere to start from the beginning.
> There are several non-programmers tutorials
> (including mine :-). Try one of them.
> Dive Into python is an excellent book for experienced
> programmers or after you have gone through one of those
> listed above.
> Alan Gauld
> Author of the Learn to Program web site
> Tutor maillist - Tutor at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor