Python: Find the index of a given string at which a given substring starts
Index of substring or "Not found".
Write a Python program to determine the index of a given string at which a certain substring starts. If the substring is not found in the given string return 'Not found'.
Sample Solution:
Python Code:
Sample Output:
7 1 Not found
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Python program to find the starting index of a given substring in a string and return "Not found" if it doesn't exist.
- Write a Python program to use the find() method to locate a substring and handle negative return values appropriately.
- Write a Python program to implement a function that searches for a substring and returns its index using a loop.
- Write a Python program to use regular expressions to determine the position of a substring and output a default message if absent.
Go to:
Previous: Write a Python program to count number of substrings with same first and last characters of a given string.
Next: Write a Python program to wrap a given string into a paragraph of given width.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.