An index that is too large is replaced by the string size : String Index « String « Python






An index that is too large is replaced by the string size

 

word = 'Help' + 'A'
print word[:2]    # The first two characters
print word[2:]    # All but the first two characters


print word[1:100]
print word[10:]
print word[2:1]

   
  








Related examples in the same category

1.String indexing: Random AccessString indexing: Random Access
2.Indices may be negative numbers, to start counting from the right. For example:
3.String indexing: from front or endString indexing: from front or end