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 First Sets

David P
David P
Courses Plus Student 1,162 Points

I have tried every which way to get the syntax correct. I know this may be an easy one, but I cannot get it to work.

I think it's a good idea for you to experiment with sets since they're a very useful part of Python. Start by creating a set variable named songs that has three song titles in it. You can use any titles you want, just make sure they're three different strings.

def songs = ('titles')
def titles = ['Song1', 'Song2', 'Song3']

1 Answer

Stuart Wright
Stuart Wright
41,118 Points

The correct syntax is:

songs = {'song1', 'song2', 'song3'}

The 'def' keyword is only used for function definitions, not variable assignments. And it's curly braces you need to create a set.

Alexander Peterson
Alexander Peterson
Courses Plus Student 3,832 Points

I just want to add, if you wanted to have a list of titles and make it into a set later:

titles = ['Song1','Song2','Song3']
set_of_titles = set(titles)