【发布时间】:2018-05-12 15:35:23
【问题描述】:
我的 python 程序有一个小问题。情况是我试图在我的数组中使用myarray.append(),但是在 python shell 中,当我在 python shell 中进行附加测试时,它会告诉我这一点:
>> l.append('1') # l is already defined
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
l.append('1')
AttributeError: 'NoneType' object has no attribute 'append'
>>
我对这个问题很困惑,但无论如何,我会让你看到代码:
l=[] #*
i=1
while True:
if 3*i<1000:
l.append(str(i)) #*
else:
break
i+=1
l=l.sort()
print l
*我认为这是问题的主要因素
我可能只是发疯了而没有意识到,但如果你能帮忙,请帮忙。
附:当我在print l 上运行程序时,它只会输出None
【问题讨论】:
-
您的代码无法按原样运行,这将导致无限循环
i+=1在 while 之外...
标签: python arrays python-2.7 nonetype