find last in string python code example
Example 1: find last appearance python
>>> s = 'hello'
>>> s.rfind('l')
3
Example 2: check strings last letter python
sample_str = 'Sample String'
last_char = sample_str[-1]
print('Last character : ', last_char)
Last charater : g
Example 3: last character of string in python
a = '123456789'
print(a[-1])
print(a[len(a)-1])
print(a[-4])
9
9
6
Example 4: lastindexof python
test_string = "abcabcabc"
res = test_string.rindex('c')
print ("The index of last element occurrence: " + str(res))
OUTPUT:
The index of last element occurrence: 8