Python Learning Notes (iii)-Advanced features

Source: Internet
Author: User

I. Slicing

Slicing operations are similar to sublist in Java, which is to get a sub-list

For example l=[' Zhangsan ', ' Lisi ', ' Wangwu '] then l[0, 2] means to start at index 0, until index 2 (excluding 2), exactly 2 elements. If the first index is 0, you can also omit it.


Below we create a 0-99 series: L = Range (100)

1. Get the top 10 numbers: L[:10]

2. Get the last 10 numbers: l[-10:] # The index of the first element of the countdown is-1

3. Get the top 11-20: l[10:20]

4. Get the first 10 numbers, one for every two: L[:10:2]

5. In all numbers, take one of each of the 5: l[:: 5]

Tuple, string ' xxx ' or unicode string u ' xxx ' can also use slice manipulation


Two. Iteration

Bbb


Three. List-generated

Ccc


Four. Generator

Ddd

Python Learning Notes (iii)-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.