Getting a List Subset: Slicing : List Sliced « List « Python






Getting a List Subset: Slicing

Getting a List Subset: Slicing
 

li = ['a', 'b', 'mpilgrim', 'z', 'example'] 
print li[1:3]                                            

print li[1:-1]                                           

print li[0:3]                                            
           
         
  








Related examples in the same category

1.List slice assignment: delete and insertList slice assignment: delete and insert
2.List slicingList slicing
3.List: display a sliceList: display a slice
4.List indices start at 0, and lists can be sliced, concatenated:List indices start at 0, and lists can be sliced, concatenated:
5.Slicing works similar to strings; use the square bracket slice operator ([ ] ) along with the index or indices.
6.List Slicing ShorthandList Slicing Shorthand