semicolon at end of python's statements
MRAB
python at mrabarnett.plus.com
Sun Sep 1 19:30:35 EDT 2013
On 01/09/2013 20:58, Antoon Pardon wrote:
> Op 31-08-13 02:09, Steven D'Aprano schreef:
>> On Fri, 30 Aug 2013 11:32:17 +0100, Fábio Santos wrote:
>>
>
>>
>> We really are spoiled for choice here. We can write any of these:
>>
>> # Option 1
>> for spam in sequence:
>> if predicate(spam):
>> process(spam)
>>
>
>>
>> Adding a fourth option:
>>
>> for spam in sequence if predicate(spam):
>> process(spam)
>>
>> saves absolutely nothing except a line and an indent level, neither of
>> which are in short supply, and gains nothing in readability over Option 1.
>
> So what is the big difference between this situation and the following:
>
> | else:
> | if condition:
> | whatever
>
> which in python we can write:
>
> | elif condition:
> | whatever
>
>
> So either is seems this was a design mistake or a line and an indent
> level can be important enough to allow a combination of controls.
>
'elif' is for cascading ifs:
if ...:
...
elif ...:
...
elif ...:
...
elif ...:
...
else:
...
Without 'elif' you would be forced to write:
if ...:
...
else:
if ...:
...
else:
if ...:
...
else:
if ...:
...
else:
...
On the other hand, for...if is much less of a problem.
More information about the Python-list
mailing list