Python Array/List

Source: Internet
Author: User

Range value

Specify range

names = ["0","a","two","three","Four","Five","Six","Seven"]Print(Names[1:4])#print one, two, three left including right not included

Fetch from a position to the end

names = ["0","a","two","three","Four","Five","Six","Seven"]Print(names[1:])#print [' One ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ']

Pick from a position to the bottom of the number

names = ["0","a","two","three","Four","Five","Six","Seven"]Print(Names[1:-3])#print [' One ', ' two ', ' three ', ' four ']

Jump to the value

names = ["0","a","two","three","Four","Five","Six","Seven"]Print(Names[0::1])#print [' 0 ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ']//from one to the beginningPrint(Names[0:-1:2])#print [' 0 ', ' two ', ' four ', ' six ']//from head to back to the second, jumping on a one fetchPrint(Names[0::3])#print [' 0 ', ' three ', ' six ']//jump from end to end with two fetching

Countdown value

names = ["0","a","two","three","Four","Five","Six","Seven"]Print(Names[5::-1])#print [' Five ', ' four ', ' three ', ' two ', ' one ', ' 0 ']//5th element to 1th element, upside down one to takePrint(Names[6:2:-2])#print [' Six ', ' four ']//6th element to 2nd element, jump backwards by one and takePrint(Names[-1:0:-2]

Python Array/List

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.