Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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