[Tutor] Another Newbie question

Lie Ryan lie.1296 at gmail.com
Wed Jun 25 17:24:57 CEST 2008


That's because you're doing it in interactive mode. In interactive mode,
the code is treated like commands, it is executed immediately after the
command is finished. You may differentiate Interactive Mode and
Normal/Coding Mode by the prompt, in Coding Mode there is no prompt
cause, in Interactive mode, there is the '>>>' (default)

Example in Interactive Mode:
>>> print 'Blah blah blah'
Blah blah blah
>>> for i in xrange(5):
...     print i
...
0
1
2
3
4
>>>

Some "commands", like 'for', 'while', dictionary literal, etc may
require more than one line, for those, the secondary prompt is shown
'...', although that depends on how you start python, if you started
python from IDLE, the secondary prompt is not, by default, shown.

That's a bit basic.

Now to the specific reason why python (interactive mode) "doesn't wait"
you to finish your command. In interactive mode, a blank line is
considered to be the end of multi-line command, so:

>>> for i in xrange(4):
...     print i
...     # The next line is empty
...
0
1
2
3
>>> 

that empty line is an instruction to start executing the multi-line
commands immediately (or another way to see it, an empty line is
considered to be the end of current instruction)



More information about the Tutor mailing list