Python:计算字符串中给定char的出现次数 [英] Python: count occurances of a given char in a string
本文介绍了Python:计算字符串中给定char的出现次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何在Python中采用 /bin/usr/proga/file.c之类的字符串并计算'/'字符的出现次数?
How would I take a string in Python like "/bin/usr/proga/file.c" and count the occurrences of the '/' character?
因此,对于上面的示例,该函数将返回4。
So, for the above example, the function would return 4.
推荐答案
"/bin/usr/proga/file.c".count("/")
这篇关于Python:计算字符串中给定char的出现次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文