Python standard library: built-in functions iter (object [, sentinel]), itersentinel

Source: Internet
Author: User

Python standard library: built-in functions iter (object [, sentinel]), itersentinel

This function returns an iteration sub-object. When the second parameter does not exist, the parameter object should be a container that supports the iteration protocol, that is, the _ iter _ () function is defined or the sequence access protocol is supported, that is, the Object Defining the _ getitem _ () function. Otherwise, a TypeError exception is returned. When the second parameter sentinel appears, the parameter object should be a callable object and the _ next _ () function is defined. When the enumerated value is equal to the Sentinel, the StopIteration exception is thrown.

Example:

# Iter () s = 'Software is the future of Shenzhen '# s is an iterable object with the _ getitem _ () method it = iter (s) # it is an iterator object, which has the _ next _ () and _ iter _ () Methods print (s) print (it. _ next _ () print (it. _ next _ () print (it. _ next _ () print (it. _ next __())

The output is as follows:

Software is the future of Shenzhen

Soft

Parts

Yes

Deep

 

 

Cai junsheng QQ: 9073204 Shenzhen


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.