如何使数组从下标 1 而不是 python 中的下标 0 开始?
基本解决这个problem在 python 中。
请您参考如下方法:
如果你真的想这样做,你可以创建一个包装列表的类,并将 __getitem__ 和 __setitem__ 实现为一个基础。例如:
def __getitem__(self, index):
return self.list[index-1]
def __setitem__(self, index, value):
self.list[index-1] = value
但是,要获得 Python 列表的全部灵 active ,您必须实现对切片、删除等的支持。如果您只想要列表的简单 View ,一次一个项目,这应该可以做到给你。”
参见 Python Documentation for Data Model有关创建行为类似于序列或映射的自定义类的更多信息。
