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