หากคุณมี tuple ของสตริงและต้องการค้นหาสตริงใดสตริงหนึ่ง คุณสามารถใช้ตัวดำเนินการ in
ตัวอย่าง
tpl = ("Hello", "world", "Foo", "bar")
print("world" in tpl) ผลลัพธ์
สิ่งนี้จะให้ผลลัพธ์ -
True
ตัวอย่าง
หากคุณต้องการตรวจสอบว่ามีสตริงย่อยอยู่หรือไม่ คุณสามารถวนซ้ำ tuple และค้นหาโดยใช้:
tpl = ("Hello", "world", "Foo", "bar")
for i in tpl:
if "orld" in i:
print("Found orld in " + i ) ผลลัพธ์
สิ่งนี้จะให้ผลลัพธ์ -
Found orld in world