【发布时间】:2020-04-27 18:55:33
【问题描述】:
我想在 python 的 while 循环中创建一个简单的列表
我正在使用此代码
def get_list(input):
create_cell = []
for line in input:
create_cell.append(line)
return create_cell
x=0
c = [x,'a','b']
while x < 5:
new_row = get_list(c)
print (new_row)
x = x + 1
它给出以下输出
[0, 'a', 'b']
[0, 'a', 'b']
[0, 'a', 'b']
[0, 'a', 'b']
[0, 'a', 'b']
我想要的输出是:
[0, 'a', 'b']
[1, 'a', 'b']
[2, 'a', 'b']
[3, 'a', 'b']
[4, 'a', 'b']
【问题讨论】:
标签: python list function loops while-loop