我有這樣的代碼:要怎樣才能與輸入[名單] .append()函數[PYTHON 3]
def add(whatlist):
inf = True
while inf == True and str(whatlist) in lists:
addtol = input('What do you want to add to list {0}? Type in STOP_ to end this process.: '.format(whatlist))
if addtol.upper() != 'STOP_':
whatlist.append(addtol)
else:
inf = False
當我輸入一個列表,解釋說:
'str' object has no attribute 'append'
我怎麼能這樣做input()
不會使我的輸入字符串?
要麼你whatlist對象是字符串或者你需要用'addtol = STR輸入轉換爲字符串(輸入())' –
可以告訴你,你叫'add'函數的代碼?那麼如何定義'lists'變量? – jdehesa
你能提一下'whatlist'和'lists'的值嗎? – voidpro