[Python] Iter & Next

less than 1 minute read


Iterable

  • 반복 가능한 것(string, list, tuple, dictionary, set, range 등)

Iterator

  • iter 함수를 통해 생성된 객체

flash = ['jay garrick', 'barry allen', 'wally west', 'bart allen']

superhero = iter(flash)
print(next(superhero))
print(next(superhero))
print(next(superhero))
print(next(superhero))

# 위와 같음
# for person in flash:
#     print(person)
jay garrick
barry allen
wally west
bart allen

Tags:

Categories:

Updated: