【发布时间】:2017-06-09 08:38:49
【问题描述】:
我对 python 中的 text.count() 函数有疑问。 假设我有以下文本,我想返回“CCC”的出现次数:
text = "ACCCGTTGCCCC"
print text.count("CCC")
为什么它返回 2 而不是 3?
【问题讨论】:
-
"返回子字符串 sub 在 [start, end] 范围内 非重叠 出现的次数。" docs.python.org/3/library/stdtypes.html#str.count