这是我的代码
def printList(stringlist):
empty = []
if stringlist is None:
print empty
else:
print stringlist
def add (stringlist, string):
string = [] if string is None else string
if stringlist is not None:
stringlist.insert(0, string)
else:
stringlist.append(1)
它以某种方式出现“AttributeError:'NoneType'对象没有属性'append'”
我最初是在寻找这样运行的代码:
>>> myList = None
>>> printList(myList)
[]
>>> for word in ['laundry','homework','cooking','cleaning']:
myList = add(myList, word)
printList(myList)
[laundry]
[homework, laundry]
[cooking, homework, laundry]
[cleaning, cooking, homework, laundry]