Do note that functions in Python have to be called and they return specific values or None
if nothing is specified.
From the Python Tutorial
The
return
statement returns with a value from a function.return
without an expression argument returnsNone
. Falling off the end of a function also returnsNone
.
Hence you need to define your function newlist
as
def newlist():
animals = ["cat","dog","mouse","rabbit","hamster","duck","chicken","goose","hedgehog"]
return animals # RETURN THE LIST
This will return the list as intended.
To get the list you need to call the function that can be done using newlist()
. Hence your main
function will look like
def main():
letters = ["A","B","C","D","E","F","G","H","I"]
letters = newlist() # CALL THE FUNCTION
print(letters)
Now when you call main
, you will get the intended output.
You do not need to create a seperate list with placeholders. You can directly call newlist
to get your list ready and working. In such a case the main
function will be reduced to
def main():
letters = newlist() # newlist returns a list, so call directly
print(letters)