Python String join() Method
join() is an inbuilt string function in Python used to join elements of the sequence separated by a string separator. This function joins elements of a sequence and makes it a string.
- Iterable – objects capable of returning their members one at a time. Some examples are List, Tuple, String, Dictionary, and Set
Return Value: The join() method returns a string concatenated with the elements of iterable.
Type Error: If the iterable contains any non-string values, it raises a TypeError exception.
Example 1: Joining with an empty string
Here, we join the list of elements using the join method.
Example 2: Joining String with lists using join()
Here, we join the tuples of elements using the join() method in which we can put any character to join with a string.
Example 3: Joining String with sets using join()
In this example, we are using a Python set to join the string.
Note: Set contains only unique value therefore out of two 4 one 4 is printed.
Example 4: Joining String with a dictionary using join()
When joining a string with a dictionary, it will join with the keys of a Python dictionary, not with values.