学习笔记

1、使用判断类型函数:isinstance

2、使用函数

3、使用递归

# -*- coding: utf-8 -*-

#filename:isnstance



movies = ["the holy grail",1975,"terry jones & terry illliam",91,["graham chapman",["michael palin","jonh clees","terry cilliam","eric idile","terry jones"]]]


print(movies[4][1][3])


for each_time in movies:

print(each_time)


print('----1.Modify the output-----')


for each_item in movies:

if isinstance(each_item,list):

for neach_item in each_item:

print(neach_item)

else:

print(each_item)

print('----2.Modify the output----')

for each_item in movies:

#判断第一层是否list

if isinstance(each_item,list):  

for neach_item in each_item:

 #判断第二层是否list

if isinstance(neach_item,list):

for deeper_item in neach_item:

print(deeper_item)

else:

print(neach_item)

else:

print(each_item)


print('----3.Modify the output----')

#使用函数

def print_list(the_list):

for each_item in the_list:

if isinstance(each_item,list):

#可以理解为:递归

print_list(each_item)  

else:

print(each_item)

print_list(movies)