【发布时间】:2013-09-22 21:12:39
【问题描述】:
list1 = ["name1", "info1", 10]
list2 = ["name2", "info2", 30]
list3 = ["name3", "info3", 50]
MASTERLIST = [list1, list2, list3]
def printer(lst):
print ("Available Lists:")
for x in range(len(lst)):
print (lst[x])[0]
当我尝试运行时,此代码返回“'NoneType' 对象不可下标”错误
printer(MASTERLIST)
我做错了什么?
【问题讨论】:
-
你犯的错误是你的空白打印函数调用错误,根据PEP8应该是
print(list[x])[0],你的错误变得更加明显。 ;) -
虽然报错信息不一样,但这基本上是和NoneType has no attribute 'something'一样的问题
标签: python python-3.x nonetype