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 Use .split() and .join()

I still don't understand the use of the .format() function and why we place other functions within it. Please clarify.

I struggled a bit on the third task of the .split() and .join() unit.

Though I completed it, I'm not convinced I know exactly why it is correct. In fact, I'd say that I don't know how to do it at all considering the fact that I don't know why it is correct. Someone please clarify the reason why it works.

Thanks in advance.

1 Answer

Tolulope, congrats on completing it.

This line of code:

sundaes = available.split(";")

as you know, splits the string into pieces, breaking the string on the semi-colons, and putting the pieces into a list, which is assigned to the variable sundaes:

This line:

menu = "Our available flavors are: {}.".format(", ".join(sundaes))

takes the pieces and combines (joins) them into a new string with the pieces separated by a comma and a space, and replaces the {} with that string. It then assigns the whole thing to the variable menu.