Menu Close

Python String join() Method

python string join

In this article, you will learn about the Python string join() method along with some examples. join function in Python is used to join items of iterable in one string and return a new string.
In the previous tutorial, we have seen the Python string istitle() method to check each word string start with an uppercase letter or not.

Python string join() method

Python join string method is used to concat a string with an iterable object.join() method return the new string which is a concatenation of the string in iterable.

It throws an exception TypeError if iterable contains any non-string value.

Syntax

The syntax of join function in Python is:-

string.join(iterable)

Parameter

join function in python takes parameter like string, list, tuple etc.

Return Type

Python string join method returns a new string which is the concatenation of string in an iterable.

Python string join example

Here we will take some example to understand Python string join method.

Example 1:

str1 = ' ' 
a = ['Programming', 'Funda']
result = str1.join(a)
print(result)

Output will be:- Programming Funda

Example 2:

str1 = ':' 
a = ['p','r','o','g','r','a','m','m','i','n','g']
result = str1.join(a)
print(result)

Output will be:- p:r:o:g:r:a:m:m:i:n:g

Example 3:

string = "-"
mystr = ("Programming", "Funda", "is", "the", "best")
result = string.join(mystr)
print(result)

Output will be:- Programming-Funda-is-the-best

Conclusion

In this tutorial, you have learned the Python string join() method to join all items in an iterable into one string. This is the most useful string method. You can join all the items in an iterable into one string with a specific separator.
I hope this tutorial will have helped you. If you like this article, please share it with your friends who want to learn Python programming.

For More Information:- Click Here

Python String istitle() Method
Python String lower() Method

Related Posts