Sunday, 15 September 2013

IndexError: string index out of range(str1[-1])

IndexError: string index out of range(str1[-1])

Here is my function:
def find_last(str1):
return str1[-1]
When i run it:
print find_last('aaaa')
I have the following error:
return str1[-1]
IndexError: string index out of range
How can I fix this?
Thanks.

No comments:

Post a Comment