Python 3 string.join() equivalent?

我一直在 python2中使用 string.join ()方法,但在 python3中似乎已经删除了它。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".

129560 次浏览

所以任何字符串 例子都有方法 join()

字符串对象有 join方法:

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

str.join()在 Python3中工作得很好,只需要正确排列参数的顺序即可

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

访问 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