[英]search sub-string from backward using Python
Wondering if there is a neat API in Python to search a string from backward (from a specific position in a string), for example, in string "Hello StackOverflow Hello Python", suppose I want to find the index of sub-string "Hello" which is previous to sub-string "Python"? 想知道Python中是否有一个整齐的API,可以从后向(从字符串中的特定位置)搜索字符串,例如,在字符串“ Hello StackOverflow Hello Python”中,假设我要查找子字符串“ Hello”的索引子字符串“ Python”之前的哪个?
thanks in advance, Lin 预先感谢林
Yes, it's called str.rindex()
. 是的,它叫做str.rindex()
。 It takes arguments sub
- a substring to look for, start
- a starting position, and end
. 它需要参数sub
(要查找的子字符串), start
(起始位置)和end
。
It is the r
everse of the index
function. 它是r
中的EVERSE index
功能。 There are some others, like rsplit
, too. 还有其他一些,例如rsplit
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.