# using rindex() test_string = "abcabcabc" # using rindex() # to get last element occurrence res = test_string.rindex('c') # printing result print ("The index of last element occurrence: " + str(res)) OUTPUT: The index of last element occurrence: 8
Here is what the above code is Doing:
1. We created a string variable test_string and assigned it a value of “abcabcabc”.
2. We used the rindex() method to get the last occurrence of the character ‘c’ in the string.
3. We printed the result.