Python standard library: Built-in functions ITER (object[, Sentinel])

Source: Internet
Author: User

This function returns an iteration sub-object. When the second argument does not appear, the parameter object should be a container that supports iterative protocols , that is, there is a __iter__ () function defined, or a sequence access protocol, which defines The __getitem__ () function of the object, otherwise the TypeError exception is returned. When the second parameter Sentinel appears, the parameter object should be a callable object that defines the __next__ () function, which throws an exception when the enumerated value equals the Sentinel . stopiteration .

Example:

#iter () s = ' software is the future of Shenzhen '   #s是一个iterable对象, it has __getitem__ () method it = ITER (s)             #it是一个iterator对象, it has __next__ () and __iter__ () method print (s) print (it.__next__ ()) print (it.__next__ ()) print (it.__next__ ()) print (it.__next__ ())

The resulting output is as follows:

Software is the future of Shenzhen

Soft

Thing

Is

Deep

Cai Junsheng qq:9073204 Shenzhen


Python standard library: Built-in functions ITER (object[, Sentinel])

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.