1

Given:

st = "banana"
print(st.count("ana"))
# => 1

How come the count is 1, it should be 2 right? please explain to me.

wjandrea
  • 28,235
  • 9
  • 60
  • 81

1 Answers1

3

As per documentation of str.count():

Return the number of non-overlapping occurrences of substring sub ...

In your case, the occurrences of "ana" are overlapping.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
jurez
  • 4,436
  • 2
  • 12
  • 20