Mega Code Archive

 
Categories / Python / String
 

Negative Indices numbers

word = "Hello world" print word[-1]     # The last character print word[-2]     # The last-but-one character print word[-2:]    # The last two characters print word[:-2]    # Everything except the last two characters