python中能不能像C那样,比如我新建一个列表,并赋100个初值为0
3 回答
慕森王
TA贡献1777条经验 获得超3个赞
标准写法: listVal = []; for i in range(100): listVal.append(0); 快速写法1: listVal = [[0]*100]; 快速写法2: listZero = [0] listVal = listZero * 100;
慕仙森
TA贡献1827条经验 获得超7个赞
>>> list=[0]
>>> list=list*100
>>> list
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> len(list)
100
添加回答
举报
0/150
提交
取消