We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Strings
- Find a string
- Discussions
Find a string
Find a string
Sort by
recency
|
3470 Discussions
|
Please Login in order to post a comment
Here's a soultion using .startswith() method
made it a recursion for giggles
def count_substring(string, sub_string): index = string.find(sub_string if index == -1: return 0 else: return 1 + count_substring(string[index+1:], sub_string)Python 3 solution
Likely not how the problem was meant to be solved, but you can also use regex lookarounds: