I'm currently working through Head First Python and I'm beginning to work on defining functions. The goal of this below program is to create a function print_lol() where it takes one argument: a list to display on the screen. The final code that works is as follows:
def print_lol(the_list):
for each_item in the_list:
if isinstance(each_item,list):
print_lol(each_item)
else:
print(each_item)
So if we put in a list like:
movies=["The Holy Grail", 1975, "Terry Jones & Terry Gilliam", 91, ["Graham Chapman", ["Michael Palin", "John Cleese", "Terr Gilliam", "Eric Idle", "Terry Jones"]]]
the will just output all the entries in this array.
My question is, why does print_lol(each_item) in the fourth line work? I understand that the logic is that the program will look at each item and if its not in a list it will just print the item but if it is how does the computer know what print_lol is? I don't think the first line adequately explains print_lol either. Is print_lol a command that comes with Python 3?