How to use Strings Count Method

Count Occurrences of a string

This small script will use Pythons count method to count the numberof occurrences of a string.

Also Read: Python Program to Count Non Palindrome words in a Sentence

s = "Count, the number     of spaces." 
print s.count(" ")

x = "I like to program in Python"
print x.count("i")

Leave a Reply

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