How Can We Help?
In this tutorial, we will explain how to use Python string join() method with basic syntax by example for better understanding.
The String join() method is a built-in function in Python. It merges the sequence into a string, and the sequence can be a tuple or list.
Syntax:
<string_value/string_variable>.join(seq)
Input Parameters:
- string / String variable : The string that we want to merge the sequence with.
- seq: This is the sequence to be merged with the string variable. It could be a list or tuple.
Python Join String With Sequence
We can merge sequence into a string by using join() built-in in Python.
Example (1)
#Print the result of join() method
str1='python'
version= ('V3-', '3.8-', '3.9')
print(str1.join(version))
Output of example (1)
V3-python3.8-python3.9
In the above example, string variable ‘str1’ is merged with the tuple variable version and returns the result as ‘V3-python3.8-python3.9’.
In this tutorial, you have learned the string join() method in Python. What is it? And how to merge sequence to a string.
Hopefully, it was clear and concise.
If you have an inquiry or doubt, don’t hesitate to leave them in a comment. We are waiting for your valuable feedback.
Similar Python String Manipulation Methods:
- count() : It counts how many times a given substring occurs in a string between the given start and end index.
- replace() : It replaces the old string value with a new string value.
- split() : It splits the string according to the passed delimiter string and returns the list of substrings.
- splitlines() : It splits the string at all newlines or the number of newlines and returns a list of each line with newlines removed.
- find() : It returns the index value of the string, where a given substring is found between the given start index and end index.
- rfind() : It works the same as the find() method but only searches from the backward in a string.
- index() : It works same like find() method only raises an exception if substring is not found in a string between given start and end index.
- rindex() : It works the same as the index() method but only searches from the backward in a string.
Related Articles
Python String – Mastering By Practical Examples (Comprehensive Guide)
Python tutorials list:
- Python tutorials list : access all python tutorials.