Skip to content

Instantly share code, notes, and snippets.

@Bhargav-Rao
Last active April 17, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bhargav-Rao/6a42f412c8e0c8cda0fc7ce8172616ff to your computer and use it in GitHub Desktop.
Save Bhargav-Rao/6a42f412c8e0c8cda0fc7ce8172616ff to your computer and use it in GitHub Desktop.

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 returns None. Falling off the end of a function also returns None.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment