Python notes-List slice Reference

Source: Internet
Author: User

Http://www.cnblogs.com/vamei/archive/2012/05/28/2522677.html

Range reference: Basic style [lower limit: Upper limit: Step length]

>>>print s1[:5]             #  from start to subscript 4 (elements of subscript 5 are not included)>>>print s1[2:]             #  from subscript 2 to final >>>print s1[0:5:2]          # from subscript 0 to subscript 4 (subscript 5 not included), take one element every 2 (the element labeled 0,2,4)>>>print s1[2:0:-1]         # from subscript 2 to subscript 1

As can be seen from the above, the upper limit is not included in the range reference when the upper limit is indicated.

Trailing element reference

>>>print s1[-1]             #  sequence last element >>>print s1[-3]             #  Third element of the penultimate sequence

Similarly, if s1[0:-1], then the last element will not be referenced (again, excluding the upper bound element itself)

Python notes-List slice Reference

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.