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()

Zac Serhus
Zac Serhus
741 Points

How do I use the help() in python to better understand "split" and "join"? Both methods, but seem to format differently.

When typing

help(split)

or

help(join)

Errors were popping up. I think I got one to work with some combination, so hopefully the above examples don't confuse the question.

Also, could anyone shine some light on why the methods split() and join() formatted differently?

Thank you!!

2 Answers

Stuart Wright
Stuart Wright
41,120 Points

These are string methods, so you can access the help using the following commands:

help(str.join)
help(str.split)
Zac Serhus
Zac Serhus
741 Points

Got it. Thanks

In the python shell:

$ my_string = ''
$ help(my_string.split)

then

$ help("".join)

Edit: I've always wanted to know why .join() in python takes the arguments in a different spot than .split(), especially since in JavaScript, for example, it's the other way around and it works like ˙my_list.join(', ')˙. But I haven't been able to find an answer.

Zac Serhus
Zac Serhus
741 Points

Hopefully we can find some enlightenment down the line.

Thank you