본문 바로가기 메뉴 바로가기

More Code

프로필사진
  • 글쓰기
  • 관리
  • 태그
  • 방명록
  • RSS

More Code

검색하기 폼
  • Category (105)
    • Referece (4)
    • Series (55)
    • Piece (19)
    • Ongoing (18)
      • PythonNET (3)
      • Thread (3)
      • Operator (2)
      • String (8)
      • Mutable (2)
    • Puzzle (9)
      • ProjectEuler (3)
      • HackerRank (2)
      • Exercise (4)
  • 방명록

Iterator [Python] class CountDown, __iter__(), __next__()

# Python 3 : Iterator class CountDown: def __init__(self, top: int): self.current = top + 1 def __iter__(self) -> 'CountDown': return self def __next__(self) -> int: self.current -= 1 if self.current < 0: raise StopIteration else: return self.current if __name__ == '__main__': c1 = CountDown(3) print(type(c1)) # for i in c1: print(i) # 3 2 1 0 c2 = CountDown(3) print(next(c2)) # 3 print(next(c2)..

Series 2018. 6. 16. 09:49
Iterator [Python] __iter__(), __next__()

# Python 3 : Iterator b = {1, 2, 3}b_iter = b.__iter__()print(type(b_iter)) # print(b_iter.__next__()) # 1print(b_iter.__next__()) # 2print(b_iter.__next__()) # 3print(b_iter.__next__()) # StopIteration

Series 2018. 6. 16. 08:25
Iterator [Python] iter(), next()

# Python 3 : Iterator a = [1, 2, 3]a_iter = iter(a)print(type(a_iter)) # print(next(a_iter)) # 1print(next(a_iter)) # 2print(next(a_iter)) # 3print(next(a_iter)) # StopIteration

Series 2018. 6. 16. 08:21
이전 1 ··· 27 28 29 30 31 32 33 ··· 35 다음
이전 다음
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/08   »
일 월 화 수 목 금 토
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함

Blog is powered by Tistory / Designed by Tistory

티스토리툴바