Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


i give parameter to my function, but Mr Craig didnt, whats the different???

i had just learn about Display The List video, and i create function similar with Mr Craig instruction, but i add a parameter there (line 19 - 22) while Mr Craig did not add any parameter, whats the different? i test my code work well same with the video

sorry for my english, i am not native speaker

shopping_list = []
def add_to_list(item):


    print("you have just add -> ", shopping_list[-1])
    print("you have {} items in your shopping list".format(len(shopping_list)))

def show_help():
    ---type HELP to get Help---
    ---type DONE to get done---
    ---type SHOW to get shopping list ---

print("What shoul we pick up for you???")

def show_list(shop_list):
    print("what you buy is ")
    for item in shop_list:
          print("> ",item)

while True:
    new_item = input("< ")
    if new_item.lower() == "done":

    elif new_item.lower() == "help":

    elif new_item.lower() == "show":


3 Answers

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

The parameter is a placeholder variable for adding the shopping list as an argument, when the show_list function is called. It's the way that the information is given to the function so it knows what to display to the terminal. :-)

Hey Faris, I agree with Jonathan above. If a parameter wasn't passed to the function, the code within the function is just performing an action on global variables available within the code. If Mr. Craig didn't include a parameter, that's likely an because his code is simply modifying a predefined variable. Generally speaking, every function should have a parameter, although some parameters can be optional UNLESS the purpose of the function is simply to modify global variables. Generally speaking, it may be best practice to add a parameter, assign the response of the action on the variable to a new one, and then return that variable (which makes the scope of the variable local instead of global). This is done to prevent the global variable from being modified. Here's an example:

my_shopping_list = ['tomatoes', 'apples', 'pears'] #define a new shopping list

def remove_item_from_list():
   my_shopping_list.pop() #remove the last item from the shopping list
   return my_shopping_list #return the global shopping list value

Here's what happens in the console

>>> print(my_shopping_list)
['tomatoes', 'apples', 'pears']
>>> remove_item_from_list()
['tomatoes', 'apples']

Considering the above, let's use another example:

my_shopping_list = ['tomatoes', 'apples', 'pears'] #define a new shopping list

def remove_item_from_list(my_shopping_list):
   a = my_shopping_list
   x = a[1]
   return a, x

Here's what happens in the console

>>> remove_item_from_list(my_shopping_list)
(['tomatoes', 'apples', 'pears'], 'apples')
>>> my_shopping_list
['tomatoes', 'apples', 'pears']

You can see that the original array of shopping list isn't impacted with this code, but it does perform an action on it. You could do the same with or without the parameter, but the value of x remains present only within the function do to local scoping and garbage collection. If you try to call the variable x outside of the function, you get this:

>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined

Hope that's helpful!

thanks a lot for the explanation, now its clear to me

Thanks Faris! Could you please mark my response as an answer to your question? Keep coding!

hey Fergus, i dont know how to mark your response to be an answer, i cant click it to be best answer or add comment both to your response