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 Basics (2015) Python Data Types Splitting and Joining

gary loo
seal-mask
.a{fill-rule:evenodd;}techdegree
gary loo
Python Web Development Techdegree Student 557 Points

05: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")?

flavors = ['vanilla','chocolate','berry']

print(', '.join(flavors))

''' The join method join each item on the flavors list by ', ' a comma and a space. '''

1 Answer

gary loo
seal-mask
.a{fill-rule:evenodd;}techdegree
gary loo
Python Web Development Techdegree Student 557 Points

Hi 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.

This 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.