conditional for-statement

David 71david at libero.it
Sun Aug 23 11:50:30 CEST 2009


Il Sun, 23 Aug 2009 01:09:04 -0700 (PDT), seb ha scritto:

> Hi,
> 
> i was wondering if there is a syntax alike:
> 
> for i in range(10) if i > 5:
>     print i

You can write

for i in filter(lambda i: i > 5, range(10)):
    print i

but 

for i in range(10):
    if i > 5:
        print i

it' better readable, and

for i in range(6,10):
    print i

it's event better.



More information about the Python-list mailing list