- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator.py
More file actions
Latest commit
43 lines (32 loc) · 690 Bytes
/
Copy pathiterator.py
File metadata and controls
43 lines (32 loc) · 690 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
iterable_value="Noodles"
iterable_obj=iter(iterable_value)
whileTrue:
try:
item=next(iterable_obj)
print(item)
exceptStopIteration:
break
print("\n")
# ---------------------------
# Example 2
classTest:
def__init__(self, limit):
self.limit=limit
def__iter__(self):
self.x=10
returnself
def__next__(self):
x=self.x
ifx>self.limit:
raiseStopIteration
self.x=x+1
returnx
foriinTest(20):
print(i)
print("\n")
# ---------------------------
# Example 3
print("List Iteration")
lista= ["Time", "for", "tea"]
foriinlista:
print(i)