[Tutor] Noob: nested if-clauses

Alan Gauld alan.gauld at btinternet.com
Mon Jan 25 15:46:10 EST 2016


On 25/01/16 15:52, STF wrote:

> It's a total fluke.  I put the indentation like this to *visually* help
> myself understand what I was going to write.

That's one of the good things about Python, if it looks right
it very often is right.

> In the Python tutorial that I was using, the author only told us to use
> indentation, without emphasizing on the size of it.

Quite right the amount is not important(syntactically at least) provided
you are consistent.

> As I'm a newbie, I'm mostly using Python IDLE but sometimes I would use
> Programmer's Notepad.

I don't know PN but IDLE will keep you right most of the time.

> Let me ask an alternative question.  Suppose I have something like this:
> ----
> 
> if condition_C:
>     instruction_10
>    instruction_11
>      instruction_12
> ----
> There are 4 spaces in front of instruction_10, 3 spaces in front of
> instruction_11 and 5 spaces in front of instruction_12.
> 
> What would happen to instruction_11 and instruction_12?  

One of the best things about Python is the interpreter.
Just try it and see. It's much faster than posting a question
here and you can be sure it's the correct answer! If you
don't understand what you see, then come here.

Just use some print statements or simple assignments
for example:

>>> if True:
...    print 'in the if'
...   print 'still here'
...      y = 5 * 6
...

what happens?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list