Tuesday, October 12

Chapter 7: Strings

>>> fruit = 'banana'
>>> length = len(fruit)
>>> last = fruit[length-1]

Alternatively, we can use negative indices, which count backward from the end of the string. The expression fruit[-1] yields the last letter, fruit[-2] yields the second to last, and so on.

No comments: