count()方法返回出現(xiàn)在范圍內(nèi)串子數(shù)range [start, end]。可選參數(shù)的start和end都解釋為片符號(hào)。
語法
以下是count()方法的語法:
str.count(sub, start= 0,end=len(string))
參數(shù)
返回值
此方法返回集中在長(zhǎng)度寬度的字符串。
例子
下面的例子顯示了count()方法的使用。
#!/usr/bin/pythonstr = "this is string example....wow!!!";sub = "i";print "str.count(sub, 4, 40) : ", str.count(sub, 4, 40)sub = "wow";print "str.count(sub) : ", str.count(sub)
當(dāng)我們運(yùn)行上面的程序,它會(huì)產(chǎn)生以下結(jié)果:
str.count(sub, 4, 40) : 2str.count(sub, 4, 40) : 1
新聞熱點(diǎn)
疑難解答
圖片精選