Skip to main content

Generator in Python

 


def gen(n):
    for i in range(n):
        yield i

g = gen(3)

# for i in g:
#     print(i)


h = "Aakash"    #---String is itrator but int has not itrator
d = iter(h)
 
    #-----The __next__() is a itrator which will print the next element of the string
# print(d.__next__())
# print(d.__next__())
# print(d.__next__())
# print(d.__next__())
# print(d.__next__())
# print(d.__next__())
# for i in d:
#     print(i)




Comments