Javatpoint Logo
Javatpoint Logo

Python String join() Method

The join() strategy is an underlying technique in Python that has a place with the string class. Concatenating or joining elements from an iterable, like a list, tuple, or string, into a single string is what this method does. The join() technique takes the accompanying syntax.

Basic Example:

Let's look at an example to illustrate the usage of the join() method:


Hello World Python Programming

The string "," which only contains one space character, is the basis for the call to the join() method in this example. There are four components in the iterable lis. The string "Hello World Python Programming" is created by concatenating the elements of lis with the separator "" using the join() method. The string is then output as a string.

It allows various iterables like: List, Tuple, String etc.



iterable : iterable object like: List, Tuple, String etc.


It returns a new string or an exception TypeError if iterable contains any non-string value.

Let's see some examples of join() method to understand it's functionalities.

Python String join() Method Example 1

A simple example which implements join() method with the List iterable, see the example below.



Python String join() Method Example 2

A list iterable join with empty string and produce a new string, see the example below



Python String join() Method Example 3

An example of join() method with Set iterable. Set contains unordered elements and produce different output each times. See the example below.



Python String join() Method Example 4

In case of dictionary, this method join keys only. Make sure keys are string, otherwise it throws an exception.



Next TopicPython Strings

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA