我是学习python 3的新手,并且请求帮助 代码:
movies = ["holy grail",1975,"terry jones",91
[ "gramham chamman",
["michael palin","john crees","eric idle","terry jones"]]]
for each_item in movies:
if isinstance (each_item,list):
for nested_item in each_item :
print (nested_item)
else:
print (each_item)
# when i type the next line with " else : "
the program (python shell) told me syntax error
我不知道如何解决它 非常感谢你
答案 0 :(得分:2)
我相信这就是你要找的东西:
movies = ["holy grail",1975,"terry jones",91,[ "gramham chamman",
["michael palin","john crees","eric idle","terry jones"]]]
for each_item in movies:
if isinstance (each_item,list):
for nested_item in each_item :
print (nested_item)
else:
print (each_item)
变化
,
。91["..."
不合法,但是不能订阅。产地:
>>>
holy grail
1975
terry jones
91
gramham chamman
['michael palin', 'john crees', 'eric idle', 'terry jones']