On Fri, Oct 23, 2009 at 7:31 PM, Peng Yu <span dir="ltr"><<a href="mailto:pengyu.ut@gmail.com">pengyu.ut@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

For example, the long string is 'abcabc' and the given string is<br>
'abc', then 'abc' appears 2 times in 'abcabc'. Currently, I am calling<br>
'find()' multiple times to figure out how many times a given string<br>
appears in a long string. I'm wondering if there is a function in<br>
python which can directly return this information.<br></blockquote><div><br></div><div>>>> 'abcabc'.count('abc')</div><div>2</div><div>>>> print ''.count.__doc__</div><div>S.count(sub[, start[, end]]) -> int</div>

<div><br></div><div>Return the number of non-overlapping occurrences of substring sub in</div><div>string S[start:end].  Optional arguments start and end are interpreted</div><div>as in slice notation.</div><div><br></div>

<div>HTH,</div><div><br></div><div>--S</div></div>