Given:
st = "banana"
print(st.count("ana"))
# => 1
How come the count is 1, it should be 2 right? please explain to me.
Given:
st = "banana"
print(st.count("ana"))
# => 1
How come the count is 1, it should be 2 right? please explain to me.
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.