当我们传递numbern
和字符串列表时,如何创建Python自定义函数来获取长度超过一个数n
的字符串列表
我尝试使用此函数,但它返回None
:
lst=['shiva', 'patel', 'ram','krishna', 'bran']
filtered_list=[]
def word_remove(n, lst):
for i in lst:
if len(i)>n:
return filtered_list.append(i)
print(word_remove(4,lst))
输出为:
None
Tags:
列表上的
append
方法不返回任何值。因此None
类型输出:
append方法不返回任何内容。因此,您需要返回整个过滤的列表
Append
函数没有返回类型。试试这个相关问题 更多 >
编程相关推荐