s.count(x) #返回x在s(指定范围[start,end])中出现的次数 word=input("请输入字符串:") blank=word.count(" ") print("其中的单词总数为:"blank+1) 单词的个数为空格数加1