-1
我写过这个功能。计算字符串中的字数?
# Function to count words in a string.
def word_count(string):
tokens = string.split()
n_tokens = len(tokens)
print (n_tokens)
# Test the code.
print(word_count("Hello World!"))
print(word_count("The quick brown fox jumped over the lazy dog."))
但输出
2
None
9
None
,而不是仅仅
2
9
返回n_tokens – pawelty
您打印结果的功能,但它返回无既然你不从它返回任何东西 –
ive修复它。致敬:) –