This article mainly introduces the python iterator and iter () function details and related information about the instance. For more information, see the next article. it mainly introduces the python iterator and iter () for more information about functions and instances, see
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