![](/img/trans.png)
[英]Python - TypeError: object of type 'NoneType' has no len()
[英]Python error: “TypeError: Object of type 'NoneType' has no len()”
我该如何解决这个错误? 我试图消除用户选择的名称数量。
names = []
def eliminate():
votes = int(input("How many people would you like voted off? "))
popped = random.shuffle(names)
for i in range(votes):
names.pop(len(popped))
print("The remaining players are" + names)
for i in range(0,6):
name = input("Give me a name: ")
names.append(name)
eliminate()
random.shuffle()
返回None
,而不是实际被洗牌的洗牌列表。 由于您想弹出列表中的最后一项,因此不需要为pop()
提供索引:
random.shuffle(names)
for i in range(votes):
names.pop()
random.shuffle(names)
不返回任何内容或返回None
。 但是,您的列表“名称”正在被洗牌。 你可以得到结果:
random.shuffle(names)
for i in range(votes):
del names[-1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.