47 iterator in python

 '''

1. using iterators we can get sequence of values 

based on demand by using next() function.

2. We can create iterators by using iter() function.

'''


l = [1,2,3,4,5]

#for i in l:

#    print(i)


#iterator creation


l = [1,2,3,4,5]

iter_obj = iter(l)


print(next(iter_obj))





print(next(iter_obj))





for i in iter_obj:

    print(' For loop ', i)


#print(next(iter_obj))


#





#





#

Comments

Popular posts from this blog

1 PYTHON PROGRAMMING

16 file handling in python

4 Tuple data types