Python lists and shards

Source: Internet
Author: User

str ="0123456789"Print("Print the No. 0 element:", str[0])Print("a negative number represents the last nth element, and 1 represents the last element of the countdown:", str[-1])Print("shard operation, Str[start:end], start is included in the result and end does not:", Str[1:5])Print("after a colon does not write the expression from start to end:", str[5:])Print("represents the second element from the bottom to the end:", str[-2:])Print("represents the second-to-last element from the reciprocal sixth element, but does not contain the penultimate element:", str[-6:-2])Print("Start does not write a representation from the beginning to end, but does not contain end:", Str[:4])Print("start and end are not written to represent the entire list:", str[:])Print("support Step, the step is a positive number for each n from start to end to print one:", Str[::2])Print("A negative step indicates that one is printed from end to start every n number:", str[::-2])Print("if end is smaller than start, the step must be negative otherwise an error occurs:", Str[-1:-6:-1])

Python lists and shards

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.