【发布时间】:2020-03-27 20:45:08
【问题描述】:
所以我需要定义一个函数来接收包含字母的列表并返回一个包含给定字母所有位置的新列表,例如lst = ['a', 'b', 'c'] 如果letter = 'a' 然后[0]。在我的代码中,我得到了
res=res.append(finallist)
AttributeError: 'NoneType' object has no attribute 'append'
我做错了什么?
def searchlist(lst,letter):
res=[]
for i in range(len(lst)):
finallist=lst.index(letter)
res=res.append(finallist)
return res
【问题讨论】:
-
这能回答你的问题吗? Python Append to a list returns none
-
从
res = res.append(finallist)中删除res =就可以了
标签: python python-3.x