Open chihweihan opened 4 months ago
老師您好,關於講義範例中
iter 與 getitem
在程式內的功能是什麼?
#實作for_in迴圈,__iter__(self),必需傳出interator物件,使用iter()會傳出iter的物件
def __iter__(self):
return iter(self.root)
#實作subscript[]
def __getitem__(self, item):
return self.root[item]
老師您好,關於講義範例中
iter 與 getitem
在程式內的功能是什麼?