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) Sets Set Basics

I don't understand what the .pop() function did. I thought it was used to delete and return a value.

.pop() value was used and not sure what it did.

1 Answer

Steven Parker
Steven Parker
229,732 Points

It does exactly what you said, it deletes an item and returns the value. So after his demonstration, the set would be empty.

However, in looking at the video again I noticed something .. the values appear in numerical order! On a list, the "pop" function removes the last item. Yet it appears that on a set, it removes the first item! But you should probably not count on that. According to the "help" documentation, on a set it will "Remove and return an arbitrary set element."