Python 3 string.join() equivalent?

PythonStringMethodsPython 3.x

Python Problem Overview


I've been using string.join() method in python 2 but it seems like it has been removed in python 3. What is the equivalent method in python 3?

string.join() method let me combine multiple strings together with a string in between every other string. For example, string.join(("a", "b", "c"), ".") would result "a.b.c".

Python Solutions


Solution 1 - Python

'.'.join() or ".".join().. So any string instance has the method join()

Solution 2 - Python

str.join() works fine in Python 3, you just need to get the order of the arguments correct

>>> str.join('.', ('a', 'b', 'c'))
'a.b.c'

Solution 3 - Python

There are method join for string objects:

".".join(("a","b","c"))

Solution 4 - Python

Visit https://www.tutorialspoint.com/python/string_join.htm

s=" "
seq=["ab", "cd", "ef"]
print(s.join(seq))

> ab cd ef

s="."
print(s.join(seq))

> ab.cd.ef

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDennisView Question on Stackoverflow
Solution 1 - PythonTimView Answer on Stackoverflow
Solution 2 - PythonhobsView Answer on Stackoverflow
Solution 3 - PythonwerewindleView Answer on Stackoverflow
Solution 4 - PythonJamil AhmadView Answer on Stackoverflow