1

when executing the command in python

str="BANANA"
print(str.count("ANA"))

give answer as 1.

but real answer would be 2. how to solve this

scharette
  • 8,489
  • 6
  • 28
  • 62
  • 3
    It works as intended. From the help of `str.count` Return the number of non-overlapping occurrences of substring sub in string S[start:end] – Chrispresso Aug 02 '18 at 16:54

1 Answers1

1

It's true that this might be misleading most tutorial sites say that count returns the number of occurences in the string, it should actually say it returns the nnumber of non-overlapping occurences in the string

Jonathan R
  • 3,060
  • 2
  • 19
  • 33