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 Collections (2016, retired 2019) Lists Shopping List Take Three

Question on Shopping List 3 script

I'm wondering why Kenneth writes the add_to_list function using both "item" and "new_item" variables when they essentially mean the same thing in this program. Based on the video, the script still works (and I guess I get why it works... since you're passing "new_item" through a function whose argument is "item", thus you can reference either one because they both point to the same thing) BUT seems like we would just pick one or the other to limit confusion.

2 Answers

andren
andren
28,558 Points

I have not completed this course myself so I could be overlooking something, but after taking a look at the code I'll have to agree with you.

He should not have used new_item, and in fact due to variable scope it in most situations would not have worked to use new_item in the way shown in this example.

I have to imagine that him using new_item was an oversight and that he meant to type item. That would be consistent with the rest of the code and is the logical and correct thing to do.

Thanks, andren!