我有这样的代码:要怎样才能与输入[名单] .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