Python: Beginner's Guide to Programming Code with Python (Python, JavaScript, Java, Code, Programming Language, Programming, Computer Programming Book 1) by Charlie Masterson

Python: Beginner's Guide to Programming Code with Python (Python, JavaScript, Java, Code, Programming Language, Programming, Computer Programming Book 1) by Charlie Masterson
Author: Charlie Masterson
Language: eng
Format: azw3, epub
Published: 2016-11-17

Now we need to add a function which will allow us to list the books. This is going to be much the same: we need to send it our list, bookList, and have it read it off. First we need to define it. I’m putting it right after our last function:

def listBooks(listOfBooks):

Now we need to transfer our logic over.

def listBooks(listOfBooks):

if not listOfBooks:

print “The list is empty!\n”

else:

for i in listOfBooks:

print “%s\n” % i

After that, we can go back to our if-statement and replace the ugly code with the far more elegant: