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 trialgary loo
Python Web Development Techdegree Student 557 Points05:00 -Why is syntax ', '.join(flavors)?
05:00 -Why is syntax ', '.join(flavors)? Why not flavors.join(', ') as per obj.mthd('param') eg. flavors.remove("mint")?
1 Answer
gary loo
Python Web Development Techdegree Student 557 PointsHi Victor, Thanks for your reply. But I dont think that's the answer. Flavors is a list and it does not have the join method, only string has the join method. Thus syntax is like that.
Victor Santiago
11,135 PointsThis is from: https://docs.python.org/2/library/string.html#string.join
string.join(words[, sep]) Concatenate a list or tuple of words with intervening occurrences of sep. The default value for sep is a single space character. It is always true that string.join(string.split(s, sep), sep) equals s.
Victor Santiago
11,135 PointsVictor Santiago
11,135 Pointsflavors = ['vanilla','chocolate','berry']
print(', '.join(flavors))
''' The join method join each item on the flavors list by ', ' a comma and a space. '''