Iterator and Next function of python , INBUILT FUNCTIONS OF PYTHON

->Iter():
a simple meaning of iterator is to "repeat a process" the iterator in python is written as " iter() ", The iter() function returns an iterator for the given object.
i.e it creates an object which can be iterated one element at a time .

for example:
 there is a list of marks of 7 students , you want to see all the marks but one by one then you use iter() function
  iter() parameters
        iter() function takes two parameters:
        object - whose iterator has to be created(lists, tuples,etc)
        sentinel(optional) - special value that is used nto represent the end of a sequence    

->next():
it works the same as of its name , the next() function returns the next item from the iterator .
it is written as next()
it has two parameters
iterator -next() takesout the next item from the iterator
default(optional) - this value is returned if tthe iterator is exhausted (there is no next item)






Comments

Post a Comment