[Tutor] Noob: nested if-clauses

STF lapsap7+python at gmail.com
Sun Jan 24 14:42:06 EST 2016


Hi,

I've just started to learn Python thru some online courses and websites.
They just teach very basic things.  I've got some questions about "if" that
I'm unable to find the answers.  So let me ask the newbie questions here.

Let's see the following instructions:
--------
if condition_A:
    instruction_1
    instruction_2
    if condition_B:
      instruction_3
      instruction_4
    instruction_5
else:
    instruction_6
--------

* How to make Pythom understand that instruction_4 is a part of condition_B
if-clause but not a direct instruction of condition_A if-clause?  And how
to make Python understand that instruction_5 is outside of condition_B
if-clause?  Just by the number of white spaces in front of every
instruction??

* How to make Python understand that "else" belongs to the first
condition_A if-clause, not to the immediate condition_B if-clause?

* Suppose I put four white spaces in front of instruction_1, and then "tab
key" in front of instruction_2, would this break things?  I ask so because
most intelligent text editors would insert automatically a tab in place of
4 white spaces after we press Enter on a line with 4 leading white spaces.

* Do I really need to keep the consistency of 4 white spaces?  Not one more
or one less?

Thanks in advance.


More information about the Tutor mailing list