我已经将fruits1
的值扩展到fruits2
,即fruits2
的所有元素都应该在fruits1
列表中。
当我尝试用remove方法删除"lemon"
时,它显示项不在列表中。你知道吗
fruits1= ["orange" , "apple"]
frutits2=["pineapple" , "lemon"]
fruits1.extends(fruits2)
fruits1.remove(lemon)
print(fruits1)
ValueError: list.remove(x): x not in list
Tags:
您的代码中有一些错误:
extend
而不是extends
frutits2
,您使用fruits2
扩展列表。你知道吗lemon = 'lemon'
的某个地方声明)。你知道吗使用以下选项:
试试
fruits1.remove("lemon")
。你知道吗您试图从列表中删除名为“lemon”的对象。它没有这样的对象。你知道吗
在代码中
fruits1.remove(lemon)
。您试图删除变量,但它是安装的字符串试试fruits1.remove('lemon')
。你知道吗相关问题 更多 >
编程相关推荐