>>> help(str.count)
Help on method_descriptor:
count(...)
S.count(sub[, start[, end]]) -> int
Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are interpreted
as in slice notation.
根据
str.count
方法的文档:因此在您的例子中,在字符串
"ACCCGTTGCCCC"
中有两个不重叠的CCC
出现。你知道吗希望有帮助。你知道吗
返回子字符串的出现次数。 在这种情况下:“ACCCGTTGCCCC” 给你2,因为你的子串是“CCC”的集合,它在字符串中只出现了两次(也就是说,其中“C”彼此相邻放置了至少3次)
最好是使用已经可用的
Counter
。你知道吗相关问题 更多 >
编程相关推荐