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 Removing Items From A List

my delete function uses if statement still same result

def delete():
  item = input('What item would you like deleted? ')
  if item in shopping_list:
    shopping_list.remove(item)

what is the difference in i understand how both work but is there a specific reason i should use the try/except block?

p.s i wrote this function before watching the video

1 Answer

Paul Melos
Paul Melos
3,905 Points

Your way is fine as well. Try/Except blocks make error handling easier as a script gets more complex. At this point since the shopping list script is still pretty simple its not technically necessary, but he's just showing best practice/style.