Zephyrnet Logo

Python Join Function

Date:

Let us learn what is Python Join function and how to implement the Python string join() method in multiple ways with examples, explanation and much more.

What is Python Join() Method?

In simplest words, the join() method is nothing but a way to concatenate two different strings, tuples or a list.

This join() method returns a concatenated string with the sequence separated the delimiter (or the separator). A sequence could be a list, tuple, dictionary or even a set.

For instance, if your string is something like “ABC” and the separator is “-“, the final output would be “A-B-C”. This is simple and straight forward.

The join() function returns a string concatenated with the elements of the sequence as well as the delimiter. If the string contains any non-string values, it raises a TypeError exception.

Syntax

  • string: This is the string defined with the delimiter or the separator.
  • string_values: This is the string defined which needs to be separated by the delimiter. This could be anything such as list, tuple, set or dictionary.

Example 1: Python Join() method with Delimiter using String

Here, we’re joining two strings in Python using the join() function. We’re using Python join with Delimiter , and we’re capturing the join functionality within a new string which incorporates the delim within the str, and returns the results.

Example 2: Python Join() method using Tuple

Here, we’re joining two strings in Python using the join() function. This is similar to the above example; the only difference is that the string is Tuple in this case.

Example 3: Python Join() method using the List of Integers

 

Here, we’re joining two lists in Python using the join() method. This is similar to the above example; the only difference is that the Tuple is List in this example.

 

Python Join Function with List, Tuple, String examples

If you have any doubts about Python Join function, let us know about it in the comment section. For more insights on Python string functions, you can check the documentation.

More Python Programs

Source: https://www.codingalpha.com/python-join-function/

spot_img

Latest Intelligence

spot_img

Chat with us

Hi there! How can I help you?