Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีหา Index ของ Last Occurrence ของ Substring ใน Python

ใช้ rfind() คืน index ของ occurrence สุดท้าย หรือ -1

ตัวอย่าง

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