python的`__getitem__`方法
发布日期:2021-05-14 15:19:52 浏览次数:17 分类:精选文章

本文共 905 字,大约阅读时间需要 3 分钟。

Python������__getitem__���������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������

class Array:
def __init__(self, capacity):
self._capacity = capacity
self._size = 0
self._data = [None] * self._capacity
def __getitem__(self, item):
return self._data[item]

������������������Array���������������������������������������������a[key]���������������__getitem__������������������

a = Array(10)
a[0] # ������__getitem__���������_data[0]

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

���������������������������������������������������������������������������

上一篇:一些面试的准备的回答
下一篇:python实现数组

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2025年05月01日 15时03分29秒