Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Indices may also be negative numbers, to start counting from the right:Indices may also be negative numbers, to start counting from the right:

>>> word = 'Python'
>>> word[-1]  # last character
'n'
>>> word[-2]  # second-last character
'o'
>>> word[-6]
'P'
>>> word[42]  # the word only has 6 characters
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>> s = 'supercalifragilisticexpialidocious'
>>> len(s)
34
Source by docs.python.org #
 
PREVIOUS NEXT
Tagged: #Indices #negative #start #counting #negative #start #counting
ADD COMMENT
Topic
Name
9+8 =