Python Advanced Features

Source: Internet
Author: User

1. Iteration


* This list or tuple can be traversed by a for loop, which iterates over the

* As long as the object can be iterated, whether or not subscript, can iterate

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9B/D2/wKioL1lnZRGhyPEJAABDQ9TsetY688.png "title=") DW@B4%4QXP) bhtv56k ' @}4.png "alt=" Wkiol1lnzrghypejaabdq9tsety688.png "/>

* Determine if an object is an iterative object, with the iterable judgment of the collections module

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9B/D2/wKiom1lnZXfQo5nvAABh7mhlSU0756.png "title=" DS8] Oks_apsc9r}ntiq_ ' 5l.png "alt=" Wkiom1lnzxfqo5nvaabh7mhlsu0756.png "/>

* Enumeration Method Emumerate, change the list to index-element pair

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9B/D2/wKioL1lnZeng4huSAAAfs_wyFTQ141.png "title=" T8bh6qj_v} ' ofo4dptfgp]e.png ' alt= "wkiol1lnzeng4husaaafs_wyftq141.png"/> * Two variables for iteration display

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9B/D2/wKioL1lnZjrzzwy_AAAnqjBvaRo036.png "title=" ry83% 5~ked% ' 1jtzd4) 3kl0.png "alt=" Wkiol1lnzjrzzwy_aaanqjbvaro036.png "/>



2. List-Generated


*python built-in for creating lists

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9B/D2/wKiom1lnZqyA2Y2fAAAaz5vt7Pw557.png "title=" q{6w% ~rjad]fscm9q8yi_vf.png "alt=" Wkiom1lnzqya2y2faaaaz5vt7pw557.png "/>


3. Generator


* Subsequent elements, so that you do not have to create a complete list, thus saving a lot of space, in Python, this side loop side of the computation mechanism, called the generator.

* Create a generator to change a list-generated [] to ()

* Read method of G.next (), for loop

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9B/D2/wKioL1lnZ92jXtleAABL7WnP7j0533.png "title=" 2] E52KE89CFXSNJ6X@58YF6.png "alt=" Wkiol1lnz92jxtleaabl7wnp7j0533.png "/> * Fibonacci cut function, change print B to yield B, function order execution, encounter return Or the last line of the function statement returns, each time the generator function calls next () executes, the yield statement is returned, and execution resumes from the last yield statement.

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9B/D2/wKioL1lnaXngey13AABrFaMQxGk398.png "title=" 4ZQKB $5ix]ppl1ramyx}4fe.png "alt=" Wkiol1lnaxngey13aabrfamqxgk398.png "/>


Python Advanced Features

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.