list append后类型为None解决方案
list append后类型为Noneimport randomred [y for y in range (1,34)]redballs []for n in range(1,7)
list append后类型为None
import random
red = [y for y in range (1,34)]
redballs = []
for n in range(1,7):
ball = red.pop(random.randint(0, (len(red)-1)))
print ball
s = redballs.append(ball)
print s
>>> ================================ RESTART ================================
>>>
6
None
16
None
1
None
12
None
19
None
33
None
>>>
想知道为什么redballs这个list的追加为啥不成功呢?错在哪里呀?实在没看出来
>>> redballs = []
>>> ball = 34
>>> redballs.append(ball)
>>> redballs
[34]
>>> ball = 45
>>> redballs.append(ball)
>>> redballs
[34, 45]
这样却可以。
没明白哪里错了,请高手指点
[解决办法]没有错,只是你不应该打印s,应该打印redballs看结果