-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathirattion.py
More file actions
55 lines (47 loc) · 767 Bytes
/
Copy pathirattion.py
File metadata and controls
55 lines (47 loc) · 767 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
50
51
52
53
54
55
# irattion
# iter is used for making a tuple or string itratable
# to use itration next is used.
# itration on a tuple.
a=("hello","vikrant","zero")
b=iter(a)
c=len(a)
for x in range(c):
print(next(b))
# itration on a string.
x="vikrant"
y=iter(x)
z=len(x)
for irt in range(z):
print(next(y))
"""
# making a itration
class no:
def __iter__(self):
self.x=1
return self
def __next__(self):
a=self.x
self.x*=2
return a
myclass=no()
hello=iter(myclass)
for g in range(10):
print(next(hello))
print("\n")
# stoping an itrartion.
class ok:
def __iter__(self):
self.x=1
return self
def __next__(self):
if self.x<=1025:
a=self.x
self.x*=2
return a
else:
raise StopIteration
myclass=ok()
so=iter(myclass)
for i in so:
print(i)
"""