The count() function returns the number of occurrences of str.exp2 within str.exp1.
count(str.exp1, str.exp2)
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. |
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,’ ’)