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

pres = pres or set()

So another newbie question... in this code challenge, the function is already populated with pres = pres or set. The default condition of pres = None. So why is it that this code selects an empty set (set()) instead of an empty variable? How is this hierarchy organized?

1 Answer

Steven Parker
Steven Parker
243,215 Points

The value "None" is considered "falsey". So when "pres" is "None", then the code "pres = pres or set()" works the same as if it were just "pres = set()".

Any recommendation on where to find the documentation for this? It makes sense but I think I need to go into the semantics of it

Steven Parker
Steven Parker
243,215 Points

You might look in the official Python documentation on Truth Value Testing and Boolean Operations.

Thank you!