本文實例講述了python統計字符串中指定字符出現次數的方法。分享給大家供大家參考。具體如下:
python統計字符串中指定字符出現的次數,例如想統計字符串中空格的數量
s = "Count, the number of spaces."print s.count(" ")x = "I like to program in Python"print x.count("i")PS:本站還提供了一個關于字符統計的工具,感興趣的朋友可以參考一下:
在線字數統計工具:
http://tools.jb51.net/code/zishutongji
希望本文所述對大家的Python程序設計有所幫助。
新聞熱點
疑難解答