[Tutor] Noob: nested if-clauses
STF
lapsap7+python at gmail.com
Fri Jan 29 12:41:05 EST 2016
On 25 January 2016 at 21:46, Alan Gauld <alan.gauld at btinternet.com> wrote:
> 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.
>
Actually, in the original example code I type on notepad, I was using
tabs. But since I can't press Tab inside Gmail interface, I pressed spaces
instead.
My incomprehension is partially due to this YouTube video:
https://youtu.be/W1zOj2CI-KQ (@ 7:00) in which the author didn't insist on
"consistency".
Another reason is that, while tab is interpreted as 4 white spaces in
convention, it's shown as 8 white spaces in Notepad. So when I opened some
source code, I have different numbers of leading white spaces, which lead
to my confusion.
Personally, I don't find this as a "good thing". It rather recalls the
horrible dreams I have had when I was using Fortran! In Fortran, we have
to deal with position of first characters to make things work. IMO, making
a visual format an essential thing in programming is a very bad idea, if
it's not superficial.
> > 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?
>
OK, I have just tried it (instead of just reading source codes) and I see
what that gives. IDLE is indeed easier to use than the "DOS-style" Python
command-line window. How do you call this thing, BTW? I'm unable to
understand how to navigate inside this thing. I mean, when I open it, in
which folder am I in? Suppose I have a Python file in
D:\mycode\abc\myfile.py. How to run it?
Thx
More information about the Tutor
mailing list