use*_*555 14 python python-3.x nonetype
list1 = ["name1", "info1", 10]
list2 = ["name2", "info2", 30]
list3 = ["name3", "info3", 50]
MASTERLIST = [list1, list2, list3]
def printer(list):
print ("Available Lists:")
listlen = (len(list))
for x in range(listlen):
print (list[x])[0]
Run Code Online (Sandbox Code Playgroud)
当我尝试运行时,此代码返回"'NoneType'对象不可订阅"错误printer(MASTERLIST).我做错了什么?
Ter*_*ryA 11
该print()函数返回None.您正在尝试索引无.你不能,因为'NoneType' object is not subscriptable.
放在[0]括号内.现在你要打印所有内容,而不仅仅是第一个术语.