python数组队列代码实例
程序员文章站
2023-03-12 11:03:38
python数组队列代码实例
class MyList:
test = []
def __init__(self, mylen=100):...
python数组队列代码实例
class MyList: test = [] def __init__(self, mylen=100): self.mylen=mylen def append(self,data): self.test.append(data) if len(self.test)>self.mylen: print("pop",self.test.pop(0))#取出第一个元素 # test.remove(test[0]) print(self.test) def get(self,index): if index<0: return None if index>len(self.test): return None return self.test[index] mlist=MyList(4) for i in range(2): mlist.append(i) print(mlist.get(0)) print(mlist.get(3))