Find and Replace Methods
Following are the Find and Replace methods in Python −
| Sr.No. | Method & Description |
|---|---|
1 |
Counts how many times sub occurs in string or in a substring of string if starting index beg and ending index end are given. |
2 |
Determine if sub occurs in string or in a substring of string if starting index beg and ending index end are given returns index if found and -1 otherwise. |
3 |
Same as find(), but raises an exception if str not found. |
4 |
Replaces all occurrences of old in string with new or at most max occurrences if max given. |
5 |
Same as find(), but search backwards in string. |
6 |
Same as index(), but search backwards in string. |
7 |
Determines if string or a substring of string (if starting index beg and ending index end are given) starts with substring sub; returns true if so and false otherwise. |
8 |
Determines if string or a substring of string (if starting index beg and ending index end are given) ends with suffix; returns true if so and false otherwise. |