semicolon at end of python's statements

Jussi Piitulainen jpiitula at ling.helsinki.fi
Sat Aug 31 03:47:05 EDT 2013


Steven D'Aprano writes:

> We really are spoiled for choice here. We can write any of these:
> 
> # Option 1
> for spam in sequence:
>     if predicate(spam):
>         process(spam)

# Option 1.5
for spam in sequence:
    if not predicate(spam): continue
    process(spam)

This saves an indent level.

> # Option 2
> for spam in filter(predicate, sequence):
>     process(spam)
> 
> # Option 3
> for spam in (spam 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.





More information about the Python-list mailing list