python-Sequence Learning Notes

Source: Internet
Author: User

1 #lists, tuples, strings are sequences, sequence common operations are shards2Item = ('Apple','Mango','Carrot','Banana')#Meta-group3List = ['Apple','Mango','Carrot','Banana']#List4 5 #indexing or ' Subscription ' Operation6 7 #takes a specified fragment, the position can be in order 0, 1 ... or reverse ... -2, -18 Print('List 0 is', list[0])9 Print('List 1 is', list[1])Ten Print('List 2 is', list[2]) One Print('List 3 is', list[3]) A Print('list-1 is', list[-1]) - Print('list-2 is', list[-2]) - Print('List 0 is%s,and Item 1 is%s'% (list[0],item[1])) the  - #slicing on a list or item - Print('Item [0,2] is', Item[0:2])#use: Split start and end positions (not included), semicolons are not saved - Print('Item [0,-1] is', Item[0:-1])#both start and end ordinal numbers can be negative, and negative numbers are reversed + Print('Item [: 3] is', List[:3])#omit start, default from 0, - Print('Item [1:] is', List[1:])#omit end, default to end (inclusive), + Print('Item [:] is', list[:])#split start and end positions can be omitted, all elements are obtained A  at #slicing on a string -Name ='Swaroop' - Print('characters [1:3] is', Name[1:3]) - Print('characters [1:3] is%s'% Name[1:3])#Note the difference from the above print statement - Print('characters [0:4] is', Name[0:4]) - Print('characters [: 5] is', Name[:5]) in Print('characters [2:] is', name[2:]) - Print('characters [1:-1] is', name[1:-1]) to Print('characters [:] is', name[:])

python-Sequence Learning Notes

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.