Iterator concept, generator Concept

Source: Internet
Author: User
Tags iterable

Iterator concept, generator Concept
Iteratable objects:

  • Objects that can be directly acted on by the for King are collectively referred to as iteration objects: Iterable
1 # to determine whether an object is an Iterable object, first import the Iterable module in collections 2> from collections import Iterable3> isinstance ([], Iterable) 4> True5> isinstance (100, Iterable) 6> Fales
Iterator
  • Can be called by the next () function and continuously return the next worthwhile object collectively referred to as the Iterator: Iterator
  • You can use the iter () function to convert non-iterator objects into iterators.
1 # determine whether an object is an Iterator object 2> from collections import Iterator3> isinstance (x for I in range (10), Iterator) 4> True5> isinstance ([], Iterator) 6> False

 

 

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.