iteration iterating over sequence of objectssuch as used in for loopis common operation to better understand how iteration workswe consider the following code hello for in sprint ( ,'*'end=' iterable iterator string is an example of python object that can be iterated one of the methods of string object is __iter__ any object that has such method is called an iterable calling this method creates an iterator -an object that returns the next element in the sequence to be iterated this is done via the method __next__ hello __iter__ ( is now an iterator same as iter(sprint ( __next__ (same as next(tprint ( __next__ (print ( __next__ ( sequence range the inbuilt functions next and iter simply call these corresponding doubleunderscore functions of an object when executing for loopthe sequence/collection over which to iterate must be an iterable during the execution of the for loopan iterator is created and the next function is executed until there is no next element an iterator is also an iterableso can be used in for loop as well liststuplesand strings are so-called sequence objects and are iterableswhere the elements are iterated by their index the most common iterator in python is the range iteratorwhich allows iteration over range of indices note that range returns range objectnot list for in range ( , )print (iend='print range ( , ) range ( , similar to python' slice operator [ ]the iterator range(ijranges from to jnot including the index sets two other common iterables are sets and dictionaries python sets areas in mathematicsunordered collections of unique objects sets are defined with curly brackets }as opposed to round brackets for tuplesand square brackets for lists unlike listssets do not have duplicate elements many of the usual set operations are implemented in pythonincluding the union and intersection