Python list Slicing

Source: Internet
Author: User
Tags python list

The Python List supports slicing.And allows us to cut out the desired data according to our own needs.

The slice of the List is mainly operated in three directions:

For example, M = [1, 2, 3, 44, 11]
1. forward index:
Direction: left to right

C = m [1: 3]
The output result is: [2, 3]

2 reverse index:
The direction is from right to left.

For example, D = m [-1]
The result is 11. The value direction is from right to left, and-1 indicates the last one.

3 default index:

If the start is omitted, the default value starts from 0, for example, M [: 3]. The result is: [1, 2, 3].
If the end is omitted, the default length is-1, for example, M [1:]. The result is: [2, 3, 44, 11].
To output all the contents of the list, use M [:]. Starts from the beginning to the end.

Related Article

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.