python counts the number of occurrences of a specified character in a string
- 2020-05-05 11:26:56
- OfStack
This example shows how python counts the number of occurrences of a specified character in a string. Share with you for your reference. The details are as follows:
python counts the number of occurrences of a specified character in a string, such as the number of Spaces in a string
s = "Count, the number of spaces."
print s.count(" ")
x = "I like to program in Python"
print x.count("i")
PS: this site also provides a tool on character statistics, interested friends can refer to:
online word count:
http://tools.jb51.net/code/zishutongji
I hope that this article has been helpful to your Python programming.