'method'对象不可订阅.不知道出了什么问题

Eco*_*tle 7 python python-3.x

我正在编写一些代码来创建一个未排序的列表,但每当我尝试使用insert方法插入一个列表时,我得到的'方法'对象不是可订阅的错误.不知道如何解决它.谢谢.

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]
Run Code Online (Sandbox Code Playgroud)

zon*_*ndo 19

你需要使用括号:myList.insert([1, 2, 3]).当你省略括号时,python认为你试图访问myList.insert位置1, 2, 3,因为这是当它们紧挨着变量时使用的括号.