count() function

The count() function returns the number of occurrences of str.exp2 within str.exp1.

Syntax

count(str.exp1, str.exp2)

Parameter(s)

str.exp1 Specifies the string expression in which to search for occurrences of str.exp2.
str.exp2 Specifies the string expression to locate within str.exp1.

Example(s)

This displays the number of spaces in the string held in the variable sentence, which is equal to 3.

sentence = "sam is home alone"
print count(sentence,’ ’)