Example-Detailed iterators and ITER () functions

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.