python统计出句中大于4个字母的单词个数
时间: 2023-06-02 20:03:44 浏览: 174
Python实现统计单词出现的个数
好的,这是一个关于Python编程的问题。可以使用split()函数将句子分割成单词,再使用for循环遍历每个单词,判断长度是否大于4个字母,累加个数即可。以下是示例代码:
```
sentence = "This sentence contains several words with more than four letters."
count = 0
words = sentence.split()
for word in words:
if len(word) > 4:
count += 1
print("There are", count, "words with more than four letters in the sentence.")
```
输出结果为:"There are 6 words with more than four letters in the sentence."
阅读全文