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

วิธีเช็คว่า Substring อยู่ใน String อื่นใน Python (ซ้ำ)

เนื้อหาเหมือน ID 1004108070

1. ใช้ keyword in

>> 'ello' in 'hello world'
True

2. ใช้ find() หา index

>> "hello world".find('ello')
1
>>> "Harry Potter: The Goblet of Fire".find('no')
-1