如何在Python的字符串中找到子字符串最后一次出现的索引?

Python有一种rfind()从字符串末尾搜索子字符串的出现的方法。如果找到,它将返回最后一次出现的索引,否则返回-1。您可以按以下方式使用它:

>>> 'some of the some'.rfind('some')
12
>>> 'some of the some'.rfind('none')
-1
>>> "NikolaTesla".rfind('kola')
2