溫馨提示×

python如何用count函數

九三
324
2021-02-09 14:19:57
欄目: 編程語言

python如何用count函數

在python中使用count函數的方法

count:count()函數的作用是用于統計字符串里某個字符出現的次數。

count()函數語法:

str.count(sub, start= 0,end=len(string))

參數:

sub:需要搜索的子字符串。

start :字符串開始搜索的位置。

end:字符串中結束搜索的位置。

count()函數使用方法:

str = "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)

輸出結果為:

str.count(sub, 4, 40) : 2

str.count(sub) : 1

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女