<分区>
我需要计算字符串中出现了多少句点(点)。
例如:
str="hellow.my.word."
代码应返回 3。
我尝试使用以下函数,但它返回字符串的长度。
num=str.count('.')
正确的做法是什么?
<分区>
我需要计算字符串中出现了多少句点(点)。
例如:
str="hellow.my.word."
代码应返回 3。
我尝试使用以下函数,但它返回字符串的长度。
num=str.count('.')
正确的做法是什么?
最佳答案
使用 str 以外的变量名(str 是内置的)。
其次:
string = "hellow.my.word."
num=string.count('.') # num=3 ...THIS WORKS
关于python - 如何计算字符串python中的句点字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37100628/