[docs] bug about syntax of "if-else" statement in the IDLE shell

Sandro Tosi sandro.tosi at gmail.com
Tue Apr 19 21:28:09 CEST 2011


Hi Victor,

On Mon, Mar 7, 2011 at 03:19, Victor Paraschiv <victorywin5 at yahoo.com> wrote:
> So, it requires me to put "else" unindented. On the other hand, if the "if--else" statement is included in the definition of a function, then it requires that "else" be exactly under "if".
> This was frustrating, when trying to learn "if-else" statement, because it took me half an hour of experimenting, before I figurred out.
> Shouldn't it be consistent?
> Could you please reply me with an explanation, in case I am wrong?

I can try to explain what I think it's happening: python interpreter
shell makes a consistent use of a prompt (either '>>> ' or '... ')
that makes commands indented by default by 4 chars. IDLE just presents
the '>>> ' for the first commands, and multiline instructions has to
be at the same level of indentation, and so the 'else' has to be at
the beginning of the line, since 'if' has no indentation.

Regards,
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi


More information about the docs mailing list