.join() method is weird

Hello,

So as we get to learn the .join() method is the opposite of the .split() method. Why does the join method act on the delimiter as if it is the string which we are modifying, why does the delimiter come before the method and the string is inserted in the following brackets? It seems counterintuitive. Aren’t we ‘acting’ on the original string?

Thanks :smile:

I don’t know that it’s considered the opposite even if it can act that way sometimes. It’s a string method and the first part is normally a string literal so you’re acting on a very specific string (often one you create on the fly)-

delim = ','
delim.join('aardvark')
delim.join(letter for letter in 'aardvark' if letter != 'a')

The second part can be any iterable that provides strings, does that make sense? So not the opposite though you could use it that way, sometimes.

Any iterable type can be joined whereas the delimiter is always the same type (a string).
You would have to define .join for each type of iterable you want to support instead of just once.