List: display a slice : List Sliced « List « Python






List: display a slice

List: display a slice
 

inventory = ["sword", "armor", "shield", "healing potion"]


begin = int(raw_input("\nEnter the index number to begin a slice: "))
end = int(raw_input("Enter the index number to end the slice: "))
print "inventory[", begin, ":", end, "]\t\t",
print inventory[begin:end]


           
         
  








Related examples in the same category

1.List slice assignment: delete and insertList slice assignment: delete and insert
2.List slicingList slicing
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