Back
How might I tally/count the occasions a given substring is available inside a string in Python?
For example:
>>> 'foo bar foo'.numberOfOccurrences('foo')2
>>> 'foo bar foo'.numberOfOccurrences('foo')
2
You can use string.count(substring), like in:
>>> "abcdabcva".count("ab")2
>>> "abcdabcva".count("ab")
Are you interested to learn the concepts of Python? Join the python training course fast!
31k questions
32.8k answers
501 comments
693 users