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

วิธีค้นหา String แบบย้อนกลับ (Backwards) ใน Python

ใช้ rfind() ค้นหาจากท้ายสตริง คืน index ของ occurrence สุดท้าย หรือ -1 ถ้าไม่เจอ

ตัวอย่าง

>> "CocacolaPepsi".rfind('cola')
4
>>> 'CocacolaPepsi'.rfind('coke')
-1