Skip to main content
 首页 » 编程设计

python for循环创建一个列表

2025年05月04日13davidwang456

<分区>

好的,伙计们, 为什么这个简单的 for 循环无法填充列表? 这是我所拥有的:

axx = [] 
for i in range(1,7): 
  axx.append('ax'+str(i)) 
  print(axx[i]) 

我收到一个错误:

Traceback (most recent call last): 
  File "./bin_data2.py", line 57, in <module> 
    print(axx[i]) 
IndexError: list index out of range 

这应该非常简单明了,不是吗? 抱歉,来自 Fortran 背景!