Python 3 string.join() equivalent?
Question:
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”.
Answers:
'.'.join()
or ".".join()
.. So any string instance has the method join()
There are method join
for string objects:
".".join(("a","b","c"))
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'
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
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”.
'.'.join()
or ".".join()
.. So any string instance has the method join()
There are method join
for string objects:
".".join(("a","b","c"))
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'
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