Skip to content

Python code snippet – check How many times a substring appears in a string?

a = '128532012'
print(a.count('0'))
#Prints: 1

print(a.count('12'))
#Prints: 2
See also  How to get started with Python?
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.