用isinstance()判断是否为列表:
lists = ['ab' , 123 , [1] , ['v'] , 'dd' , [[1] , [12333]]]
def isList(items):
if not isinstance(items , list):
#不要用return ,不然执行为None
print(items)
else :
for item in items:
isList(item)
isList(lists)
执行结果:
ab
123
1
v
dd
1
12333
网友评论