写一个函数,输入一行字符,将此字符串中最长的单词输出。
时间: 2023-12-18 19:35:19 浏览: 19
```python
def find_longest_word(sentence):
words = sentence.split()
longest_word = ""
for word in words:
if len(word) > len(longest_word):
longest_word = word
return longest_word
```
使用方法:
```python
sentence = "这是一个测试句子"
print(find_longest_word(sentence))
```
输出: "测试"
阅读全文
相关推荐












