【发布时间】:2016-02-08 00:54:44
【问题描述】:
我正在编写一些代码来创建一个未排序的列表,但是每当我尝试使用插入方法插入一个列表时,我都会得到“方法”对象不可下标错误。不知道如何修复它。谢谢。
class UnsortedList:
def __init__(self):
self.theList = list()
def __getitem__(self, i):
print(self.theList[i])
def insert(self, lst):
for x in lst:
try:
self.theList.append(float(x))
except:
print("oops")
myList = UnsortedList()
myList.insert[1, 2, 3]
【问题讨论】:
标签: python python-3.x