Slicing works similar to strings; use the square bracket slice operator ([ ] ) along with the index or indices. : List Sliced « List « Python






Slicing works similar to strings; use the square bracket slice operator ([ ] ) along with the index or indices.

 

aList = [123, 'abc', 4.56, ['inner', 'list'], 7-9j]
aList[0]
print aList[1:4]
print aList[:3]
print aList[3][1]

   
  








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.Getting a List Subset: SlicingGetting a List Subset: Slicing
6.List Slicing ShorthandList Slicing Shorthand