#add pre here to figure out the number of 0's you need, naming the variable n.listofzeros = [0] * n
如果您希望将其放入函数中,只需放入该代码并添加
return listofzeros
看起来像这样:
def zerolistmaker(n): listofzeros = [0] * n return listofzeros
样本输出:
>>> zerolistmaker(4)[0, 0, 0, 0]>>> zerolistmaker(5)[0, 0, 0, 0, 0]>>> zerolistmaker(15)[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]>>>


![python中的零列表[重复] python中的零列表[重复]](http://www.mshxw.com/aiimages/31/611957.png)
