forked from navinreddy20/Python-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIterator.txt
More file actions
49 lines (36 loc) · 739 Bytes
/
Iterator.txt
File metadata and controls
49 lines (36 loc) · 739 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
dec.py
--------------------------------------------------------------------------------
# nums = [7,8,9,5]
#
#
# # for i in nums:
# #
# # print(i)
#
#
# it = iter(nums)
#
# print(it.__next__())
#
# print(next(it))
#
# for i in nums:
# print(i)
class TopTen:
def __init__(self):
self.num = 1
def __iter__(self):
return self
def __next__(self):
if self.num <= 10:
val = self.num
self.num += 1
return val
else:
raise StopIteration
values = TopTen()
print(next(values))
# print(values.__next__())
# print(values.__next__())
for i in values:
print(i)