This article mainly introduces the Python iterator and the ITER () function in detail and examples of relevant information, the need for friends can refer to the following
Python in Iterators and ITER () functions
Iterators provide an interface for class sequence objects with a sequence of classes. Python's iterations seamlessly support sequence objects, and it also allows programmers to iterate over non-sequential types, including user-defined objects. Iterators are handy, you can iterate over objects that are not sequences but behave in sequence, such as dictionary keys, rows of a file, and so on. The role of iterators is as follows:
• Provides an iterative interface for engraved expansion;
• Performance enhancements for list iterations;
• Improved performance in dictionary iterations;
• Create a real iterative interface instead of the original object access;
• Backward compatibility with all existing user-defined classes and objects that extend the simulated sequence and mappings;
• You can create more concise and readable code when iterating over non-sequential collections, such as mappings and files
#iter and generator#the First try#=================================i = iter (' ABCD ') print i.next () print i.next () print I.next () s = {' One ': 1, ' both ': 2, ' three ': 3}print SM = iter (s) print m.next () print m.next () print m.next ()
D:\Scirpt\Python\Python Advanced Programming >python ch2_2.py
abc{' three ': 3, ' one ': 2, ' one ': 1}threetwoone
"Recommended"
1. Python Basics Free Tutorial
2. Python Learning Manual
3. Python meets data collection video tutorial