我是 python 和学习的新手。如所给出的here https://www.tutorialspoint.com/python/string_count.htm count()
方法在字符串上使用时给出子字符串在字符串中出现的次数。
所以当我这样做时:
'BANANA'.count('ANA')
预期输出应为 2,因为“ANA”在“BANANA”中出现两次,但是count
返回 1。
有人可以解释一下吗,或者我可能误解了什么。
请为我指明正确的方向。
>>> 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.
注意不重叠.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)