Find
find is a Python string method that returns the lowest index of a specified substring, or -1 when the substring is absent.
Python How-To
The Python str.find method returns the lowest index at which a specified substring occurs, or -1 if it is absent.
- How it is used
- Uses string substring searches where absence should produce a testable result instead of an exception.
- How deep it goes
- Defines the return values, string-only scope, and basic conditional pattern, but does not explain implementation internals.
- Examples
- Demonstrates checking a returned index and filtering task titles, descriptions, and completion notes.
- What you can do after
- Apply it via Python strings to locate substrings and branch safely when no match exists.
Get Programming: Learn to code with Python
find is a Python string method that returns the lowest index of a specified substring or -1 when the substring is absent.
- How it is used
- Uses substring searches to inspect text and locate separators in user input.
- How deep it goes
- Explains case sensitivity, indexing, first matches, missing matches, and a slicing application, but stops short of implementation internals.
- Examples
- Demonstrates searches in "some_string" and "me myself and I", then splits names such as "Aqua Man" using a space.
- What you can do after
- Apply it to locate substrings or separators, test whether text is present, and guide string slicing.
Read how Get Programming: Learn to code with Python explains find →
Also covered in
What to know first
- ValueErrorValueError is a built-in Python exception raised when an operation receives an argument of an appropriate type but an inappropriate value.
Related concepts
- rfindalternative to · rfind is a Python string method that returns the highest index at which a specified substring begins, or -1 if it is absent.
- __str__part of · __str__ is a Python special method that returns an object's informal, human-readable string representation.
- string moduleuses · The string module is a Python standard-library module providing constants and utilities for processing text and character classes.
- substringuses · A substring is a contiguous sequence of characters contained within a larger string or character sequence.
- indexingproduces · Indexing is the process of assigning or using positions, keys, or lookup structures to identify and access elements or records.
Questions about find
What is find?
find is a Python string method that returns the lowest index of a specified substring, or -1 when the substring is absent.
Which Manning books explain find?
Python How-To and Get Programming: Learn to code with Python.
What should I know before learning find?
Manning books that teach find usually introduce ValueError first.
What is the difference between find and index?
find is a Python string method that returns the lowest index of a specified substring, or -1 when the substring is absent. index is a Python sequence method that returns the zero-based position of the first matching value or substring and raises ValueError when none is found.
What is find part of?
Find is part of __str__. __str__ is a Python special method that returns an object's informal, human-readable string representation.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

