380 B
380 B
如何使用字符串计数方法
原文:https://www.pythonforbeginners.com/code-snippets-source-code/strings-count-method
计算字符串的出现次数
这个小脚本将使用 Pythons count 方法来计算一个字符串出现的次数。
s = "Count, the number of spaces."
print s.count(" ")
x = "I like to program in Python"
print x.count("i")