[Tutor] for: how to skip items

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Feb 17 17:24:09 CET 2014


On 17 February 2014 16:17, Gabriele Brambilla
<gb.gabrielebrambilla at gmail.com> wrote:
> Doesn't exist a way in Python to do like in C
>
> for i=0, i<100, i=i+10
>
> ? without creating a list of index?

You haven't said which Python version you're using. In Python 2 the
range function returns a list but the xrange function returns an
iterator. In Python 3 the range function returns an iterator.

Assuming you're using Python 3 then you can just do:

for i in range(0, 100, 10):
    print(a100[i])


Oscar


More information about the Tutor mailing list