python特殊函數__len__(self)

__len__ 若是一個類表現得像一個list,要獲取有多少個元素,就得用len()函數。html 要讓len()函數工做正常,類必須提供一個特殊方法__len__(),它返回元素的個數。python 例如,咱們寫一個 Students 類,把名字傳進去:web class Students(object): def __init__(self, *args): self.
相關文章
相關標籤/搜索