Count Occurrences of a string

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

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 *