comments and the continuation prompt

Steve D'Aprano steve+python at pearwood.info
Sun Jun 25 22:04:04 EDT 2017


On Mon, 26 Jun 2017 08:44 am, Stefan Ram wrote:

>   When I enter »12\«, I get a continuation prompt in the
>   Python 3.6 console:
> 
>>>> 12\
> ...
> 
>   . I thought that this might indicate that the logical line
>   is not terminated yet.

No. You get the level 2 prompt (sys.ps2) for a number of reasons:

- after statements that require a block (def, class, if, while, for, 
  with, try, and any others I have missed);

- in triple-quoted strings;

- bracketed expressions which haven't been closed yet ( [ { 

- after comments.

 
>   According to The Python Language Reference Release 3.6.0,
>   2.1.3 Comments, »A comment signifies the end of the logical
>   line unless the implicit line joining rules are invoked.«.
> 
>   So, why do I get a continuation prompt when I enter a comment?

Why not? As far as the interactive interpreter is concerned, you haven't yet
entered a statement.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list