List slicing : List Sliced « List « Python






List slicing

List slicing
 


numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print numbers[3:6]

print numbers[0:1]

print numbers[7:10]

print numbers[-3:-1]

print numbers[-3:]


print numbers[:3]

print numbers[:]
           
         
  








Related examples in the same category

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