自定义在列表头部添加元素的方法,即insert_head 方法

摘要: class Mylist(list): def insert_head(self, n): # 下面这种方法是不可行的,在这个方法中insert_head(2)的结果就是[3, 4, 5] # L = [n] # 开辟了新的对象空间 # for x in self: # L.append(x) # 阅读全文
posted @ 2018-11-28 00:49 天蓝云败北 阅读(2247) 评论(0) 推荐(0)

自定义的类创建的对象使用len(x)函数和abs(x)函数

摘要: class Mylist: '''自定义的容器类,内部使用内建的列表保存数据''' def __init__(self, iterable): self.data = [x for x in iterable] def __repr__(self): return "Mylist(%s)" % se 阅读全文
posted @ 2018-11-28 00:39 天蓝云败北 阅读(405) 评论(0) 推荐(0)