List offset: start at zero, negative and slicing : List Indexing « List « Python






List offset: start at zero, negative and slicing

List offset: start at zero, negative and slicing
 

L = ['spam', 'Spam', 'SPAM!']

print L[2]                               # offsets start at zero

print L[-2]                              # negative: count from the right

print L[1:]                              # slicing fetches sections


           
         
  








Related examples in the same category

1.List value assignment and index referenceList value assignment and index reference
2.Negative List IndicesNegative List Indices
3.Change individual elements of a listChange individual elements of a list
4.Reference index in a list in Python.Reference index in a list in Python.
5.Searching a list for an integer.
6.List: display one item through an indexList: display one item through an index