Pythonシーケンススライス操作


'''
Created on 2011-11-1
  、   、       ,         
@author: dudong0726
'''

if __name__ == '__main__':
    
    item = ('apple','orange','tomato','egg','peer')  #  
    
    list = ['apple','orange','tomato','egg','peer']  #    
    
    print('item[0] is %s , and list[0] is %s' % (item[0],list[0])) #        ,      0、1...   ...-2、-1
    
    print('item[0,2] is ',item[0:2])  # :           (   ),     
    
    print('item[0,-1] is ',item[0:-1])  #            ,     
    
    print('item[:2] is ',list[:2]) #    ,   0,
    
    print('item[1:] is ',list[1:]) #    ,     (  ),

    print('item[:] is ',list[:])  #               ,