control structures and functions here is final version of the list_find(functionthis time using exceptionhandlingdef list_find(lsttarget)tryindex lst index(targetexcept valueerrorindex - return index herewe have effectively used the try except block to turn an exception into return valuethe same approach can also be used to catch one kind of exception and raise another instead-- technique we will see shortly python also offers simpler try finally block which is sometimes usefultrytry_suite finallyfinally_suite no matter what happens in the try block' suite (apart from the computer or program crashing!)the finally block' suite will be executed the with statement used with context manager (both covered in can be used to achieve similar effect to using try finally block one common pattern of use for try except finally blocks is for handling file errors for examplethe noblanks py program reads list of filenames on the command lineand for each one produces another file with the same namebut with its extension changed to nband with the same contents except for no blank lines here' the program' read_data(functiondef read_data(filename)lines [fh none tryfh open(filenameencoding="utf "for line in fhif line strip()lines append(lineexcept (ioerroroserroras errprint(errreturn [finallyif fh is not nonefh close(return lines