Indices may be negative numbers, to start counting from the right. For example : String Index : String PYTHON examples


PYTHON examples » String » String Index »

 

Indices may be negative numbers, to start counting from the right. For example


 

word = 'Help' + 'A'


print word[-1]     # The last character
print word[-2]     # The last-but-one character
print word[-2:]    # The last two characters
print word[:-2]    # All but the last two characters

   
  



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo String
» String Index