Why does .join() not end with the delimiter?

Continuing the discussion from If you do a join() after a split() using the same delimiter, does this result in the original string?:

I think I’m missing something in the .join() method. If this method takes each element in the list and attaches a delmiter to it, why isn’t the delimiter following the last element on the list?
var = [“I”, “Love”, “Apples”]
is I use “" as my delimiter shouldn’t " ".join(var) return "ILoveApples” as opposed to “ILoveApples”

If I’m understanding you correctly the starting string is actually used as a separator so it only occurs between the concatenated strings and not at the start or end.

If you’re posting code to the forums please have a look at: How do I format code in my posts?. It’ll help you keep the actual code (rather than being marked up by the forum formatting).

1 Like