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

Python Python Basics (2015) Shopping List App Second Shopping List App

Format of function

def addlist(new_item):

Why we have written new_item next to addlist What if we didn't write that.

1 Answer

Since this is the definition of the function, you can choose how many arguments the function should accept. If you remove the new_item variable from the definition, then your function will not take any variables as input.

In order to use new_item inside of the addlist function, it must be in those parentheses ( ). If you remove it from the definition, but try to use the function, you will receive an error.

def addlist():

new_item = 'apples'

The code above results in an error message: TypeError: addlist() takes 0 positional arguments but 1 was given