Generators and Yield keyword in Python
def generator(n):
for i in range(n):
yield i
g = (generator(4))
print(iter(g))
print(g) # code from line 6-8 is equivalent
print(g.__iter__())
print(g.__next__()) # code from line 10-12 is equivalent
print(iter(g).__next__())
print(g.__iter__().__next__())
################################
name = "abdur"
print(iter(name))
i = iter(name)
print(i.__next__())
print(i.__next__())
print(i.__next__())
print(i.__next__())
print(i.__next__())
Comments
Post a Comment
Write something to CodeWithAbdur!