Open this example in the interactive library
Source code
print('banana'.count('an'))Sample output
2

Count a substring. A self-contained example using the Python standard library.
Open this example in the interactive library
print('banana'.count('an'))2