i want to know how to calculate number of sub String available with in a string in python
You most explain better,there are several scenarios for this.
Look at this.
>>> s = 'foo bar foo bar foo' >>> len(s.split()) 5
So 5 substring in s.
>>> s[:2] 'fo'
"fo" is a substring of s.
import re [m.start() for m in re.finditer('oo', s)] [1, 9, 17]
"oo" is substring,to find all i use regex.
>>> s = 'ttt' >>> [m.start() for m in re.finditer('(?=tt)', s)] [0, 1]
Find overlapping matches
Also look at build in string function can help.
>>> help(s.find) Help on built-in function find: find(...) S.find(sub[, start[, end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. >>>