'Count, the number of spaces'.count(' ') code example Example: count number of spaces in string python >>> a = "My test string" >>> a.count(' ') 2