如何在Python中实现字长函数

问题描述 投票:0回答:1

我正在开发一个Python函数word_lengths,它接受一个字符串作为输入,并应该返回一个包含字符串中每个单词的长度的列表。我在尝试实现此操作时遇到了[特定问题/错误]。这是我当前的代码:

def word_lengths(input_string):
    
result = word_lengths("Hello world")
print(result)
python input string-length maxlength variable-length
1个回答
-1
投票
def word_lengths(input_string):
    return len(input_string)

result = word_lengths("Hello world")
print(result)
© www.soinside.com 2019 - 2024. All rights reserved.