count Method to retrieve the number of times a specified string appears in another string , If the retrieved string does not exist , Then return to 0, Otherwise, return the number of occurrences .
str.count(sub[,start[,end]])
In this way , The specific meaning of each parameter is as follows :
>>> str = "c.biancheng.net"
>>> str.count('.')
2
>>> str = "c.biancheng.net"
>>> str.count('.',1)
2
>>> str.count('.',2)
1
I talked about it before. , The retrieval value corresponding to each character in the string , from 0 Start , therefore , Retrieve values in this example 1 Corresponding to No 2 Characters ‘.’, From the output we can analyze , Retrieve from the specified index location , It also includes the index location .
>>> str = "c.biancheng.net"
>>> str.count('.',2,-3)
1
>>> str.count('.',2,-4)
0