semicolon at end of python's statements

Fábio Santos fabiosantosart at gmail.com
Mon Sep 2 06:42:53 EDT 2013


On 09/02/2013 10:45 AM, Antoon Pardon wrote:
> Op 02-09-13 10:05, Steven D'Aprano schreef:
>> It doesn't keep a whole chain of
>> if clauses together. It doesn't let you do anything that you haven't
>> already done. It just saves an indent and a newline. The cost, on the
>> other hand, includes the risk that people will try to do this:
>>
>> for item in seq: if cond:
>>      do_this()
>>      do_that()
>>      else:
>>          do_something else()
>>
>> which is clearly nonsense. Worse is this:
>>
>> for item in seq: if cond:
>>      do_this()
>>      do_that()
>> else:
>>      do_something else()
>>
>> which is still nonsense but won't raise SyntaxError.
> Why shouldn't this raise a SyntaxError?
>
Because it would be parsed as a valid for .. else construct. Either that 
or become ambiguous to the programmer, who would not be sure whether he 
was writing an else clause for the `if`, or for the `for`.



More information about the Python-list mailing list