find() / in
Finds whether/where a piece is in the text.
Syntax
text.find(part) · part in text
Description
find() gives the starting position (index) of the part, or returns -1 if not found. If you are just checking whether it exists, 'part in text' is more readable (True/False).
Returns
The position (int) or True/False.
Example
Loading editor…
Expected output
3 True
When to use?
A search box, checking whether a word appears in some text.