Instance details iterator and iter () function

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


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.