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

mohammed abdi abdulahi warsame
mohammed abdi abdulahi warsame
4,926 Points

what can we use the joinig and spliting for when we are coding python!! what is the point to split the words and join in

thank you

1 Answer

Kevin Meinhardt
seal-mask
.a{fill-rule:evenodd;}techdegree
Kevin Meinhardt
Front End Web Development Techdegree Student 5,740 Points

.join(0 and .split() are used to break up data, and put it back together. Since you can join or split a list or a string, it is great for passing information from one place to another. Let's say for example you had a form on a webpage, asking someone to select their favorite flavors of ice cream.

chocolate strawberry kiwi vanilla

For this example, let's say someone selected chocolate, and kiwi, because why not.

This selection could be passed to python on the back end as a list, then 'joined' into a string that could be formatted into a sentence that is sent back to the user.

That is a super basic example, there are probably 1.3 x Inf other ways of using split and join.

A much more complex application would be encoding information in a string. say you had a string "3dx-fifty-xyz" This string could actually be a way of storing more complex information in a simple easy to manipulate format. you could split off a chunk of this information that could then be passed to a function, or something else....