String Methods
str.find()
Locate the first occurrence of a substring entirely within the requested bounds. Return an absolute code-point offset in the original string, not an offset from start. Return -1 for a missing match; use in for a Boolean membership test and never use the result as a truth test. Empty substrings match boundaries, but a start beyond the original length does not match. The original string is unchanged.
Formal Syntax & Structure
python syntaxpython
text.find(sub[, start[, end]])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| sub | str | Substring to locate or count. |
| start | int | None | Optional inclusive start bound; negative values are relative to the end. |
| end | int | None | Optional exclusive end bound; defaults to the end. |
Return Value
int
Absolute matching index, or -1 if absent.
Working Example
Example Snippetpython
path = "item/item"print(path.find("item"))print(path.find("item", 1))print(path.find("missing"))