Python ไม่มีเมธอด contains แต่ใช้ได้ 2 วิธี:
1. ใช้ keyword in
>> 'ello' in 'hello world' True >>> 'no' in 'hello' False
2. ใช้ find() หา index
คืน -1 ถ้าไม่เจอ
>> 'hello world'.find('ello')
1
>>> 'hello'.find('no')
-1
Python ไม่มีเมธอด contains แต่ใช้ได้ 2 วิธี:
in>> 'ello' in 'hello world' True >>> 'no' in 'hello' False
คืน -1 ถ้าไม่เจอ
>> 'hello world'.find('ello')
1
>>> 'hello'.find('no')
-1