程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[python] count() method

編輯:Python

count() Method is used to count the number of occurrences of a character or substring in a string

Optional parameters are at the beginning and end of string search

grammar

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

Parameters

sub : The search of Substring

start : Where the string starts searching

          The default is the first character , The first character index value is 0

end : Where to end the search in the string

        The index of the first character in the character is 0, Default to the last position of the string

Return value

This method returns the number of times the substring appears in the string

str = "this is string example....wow!!!"
sub1 = "i"
# str.count(sub1, 4, 40): 2
print("str.count(sub1, 4, 40):", str.count(sub1, 4, 40))
# str.count(sub): 1
sub2 = "wow"
print("str.count(sub2):", str.count(sub))

Python count() Method | Novice tutorial


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved