1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Why isn't range getting exhausted in Python 3?

Discussão em 'Python' iniciado por Stack, Novembro 30, 2025.

  1. Stack

    Stack Membro Participativo

    If I do the following:

    a = range(9)

    for i in a:
    print(i)

    # Must be exhausted by now
    for i in a:
    print(i)

    # It starts over!


    Python's generators, after raising StopIteration, normally stop looping. How then is range producing this pattern - it restarts after every iteration.

    Continue reading...

Compartilhe esta Página