可以用python中的if …… else: ……
isinstance()允许检查某个特定标识符是否包含某个特定类型的数据
例如:
>>>movies =["laiba","zouba",["huba","weiba","chiba",["leba","xiaoba","xiangkaiba"]]]
>>> for each_a in movies:
if isinstance(each_a,list):
for each_b in each_a:
if isinstance(each_b,list):
for each_c in each_b:
print(each_c)
else:
print(each_b)
else:
print(each_a)
在python中创建一个函数:
要用def语句定义Python函数,为函数提供一共函数名,并在括号里指定一个参数表,参数表也可以为空。
def test(each_test):
XXXX
例如:(定义函数)
>>>def print_lol(the_list):
for each_item in the_list:
if isinstance(each_item,list):
print_lol(each_item)
else:
print(each_item)
调用函数:
>>> print_lol(movies)