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".
Joining Strings with the '+' Operator. Concatenation is the act of joining two or more strings to create a single, new string. In Python, strings can be concatenated using the '+' operator. Similar to a math equation, this way of joining strings is straight-forword, allowing many strings to be “added” together.
The Python join() function is used to join all the elements from the iterable and create a string and return it as an output to the user. Python join() returns a new string which is the concatenation of the other strings in the iterable specified.
You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.
join() function in Python Combine them into a sentence with the join(sequence) method. The method is called on a seperator string, which can be anything from a space to a dash. This is easier than using the plus operator for every word, which would quickly become tedious with a long list of words.
'.'.join()
or ".".join()
.. So any string instance has the method join()
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With