所以我有這個代碼:
class matrix:
def __init__(self, matriceOrigine: list) -> None:
self.length = len(matriceOrigine)
self.matrice = list(matriceOrigine)
def transpose(self) -> list:
pass
def transition(self, lam: float) -> list:
pass
當我創建一個實體時,像這樣:
foo = [[1,2,3],[4,5,6]]
foo2 = matrix(foo)
要訪問一個值(例如 3),我知道我應該這樣做
foo2.matrice[0][2]
我想知道如何使用
foo2[0][2]
并且仍然使用
foo2.transpose()
foo2.length
提前致謝 !
uj5u.com熱心網友回復:
定義__getitem__函式以允許自定義索引:
def __getitem__(self, index):
return self.matrice.__getitem__(index)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/440094.html
