Python题:求一句英文句子的单词数.“Winter is coming'
发布网友
发布时间:2024-10-02 01:33
我来回答
共3个回答
热心网友
时间:2024-10-25 12:04
运行结果:
please input your sentence
Winter is comming
the count is: 3
热心网友
时间:2024-10-25 12:02
import re
s="Winter is coming"
result=re.findall("\w+",s)
print(f"{result=}")
print(f"total words:{len(result)}")
'''
result=['Winter', 'is', 'coming']
total words:3
'''
热心网友
时间:2024-10-25 11:59
sentence = "Winter is coming"
word_count = len(sentence.split())
print("单词数为:", word_count)