• Python Join() Method with Examples

    Python Join Method

    In this article, we will see what is Python Join method with examples. This Python join() method tutorial helps you in implementing this concept and get a tight grip over this. 

    Python String join() Method

    It allows an iterable as the input parameter and joins their elements into a string with some of the string separator such as comma, space, underscores, etc., We can also send a string value such as “ABC” or “XYZ” etc., It returns a string by concatenating all the elements of an iterable, separated by a string separator. It joins a sequence of types like List, Tuple, String, Dictionary, & Set and converts them into a String.

    Join() Method Syntax:

    Following is the syntax of join() method.

    String: str is the name of the string in which joined elements of iterable will be stored.
    Parameter: Iterable is a parameter and we have to pass only iterable parameter. The returned values are strings. Some examples are List, Tuple, String, Dictionary, and Set.
    Return Value: It returns a string by concatenating all the elements of an iterable, separated by a string separator.
    Type Error: If the iterable contains any non-string values, it raises an exception called TypeError exception.

    Python string method join() with Examples

    Let’s move forward and see some examples using join method by taking a sequence of each data type one by one.

    Example 1: The join() method with List as Iterable

    Output:

    Example 2: The join() method with Tuple as Iterable

    Output:

    Example 3: The join() method with dictionaries as Iterable

    The join() can take a dict and concatenate all its key fields as one.

    Output:

    Example 4: The join() method with Set as Iterable

    Output:

    Also Read:

    Sharing is caring.

    Share on facebook
    Facebook
    Share on twitter
    Twitter
    Share on linkedin
    LinkedIn

    Like This Post?

    We have a lot more where that came from?

    We only send really good stuff occasionally, promise.

    Rajkumar SM

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    Share on facebook
    Share on google
    Share on twitter
    Share on linkedin
    Share on whatsapp

    Recent Posts:

    Scroll to Top
    API Testing eBook

    DOWNLOAD FOR FREE