【发布时间】:2021-03-18 20:49:14
【问题描述】:
假设我想在 python 中实现一些具有额外结构的 list 类,比如一个新的构造函数。我写道:
import random
class Lis(list):
def __init__(self, n):
self = []
for i in range(n):
self.append(random.randint(0, 30))
现在Lis(3) 给了我一个空列表。我不知道我哪里做错了。
【问题讨论】:
标签: python constructor