Python iterator and iter () function details and examples, pythoniter
Iterator and iter () functions in python
The iterator provides an interface for class sequence objects. Python iterations seamlessly support sequence objects and allow programmers to iterate non-sequence types, including user-defined objects. The iterator is very clever to use. You can iterate objects that are not sequences but represent sequence behavior, such as Dictionary keys, a file row, and so on. The functions of the iterator are as follows:
• Provides an extension iterator interface;
• It improves the performance of list iteration;
• Improved performance in dictionary iteration;
• Create a Real Iterative interface instead of the original instant object access;
• Backward compatibility with all existing user-defined classes and objects that have extended simulation sequences and mappings;
• You can create more concise and readable code for iterative non-sequential sets (such as ing and files)
# Iter and generator # the first try #================================ = I = iter ('abc ') print I. next () print I. next () print I. next () s = {'one': 1, 'two': 2, 'three ': 3} print sm = iter (s) print m. next () print m. next () print m. next ()
D: \ Scirpt \ Python advanced programming> python ch2_2.py
Abc {'three ': 3, 'two': 2, 'one': 1} threetwoone
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!