Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
What is Join() in Python?
3.
Syntax of Python join() Function
4.
Python join() Parameters
5.
Return Value of join() in Python
6.
String join() in Python Examples
6.1.
The join() method with sets
6.2.
Python
6.3.
The join() method with dictionaries
6.4.
Python
7.
Frequently Asked Questions 
7.1.
What is Join() in Python?
7.2.
What is join and split in Python?
7.3.
How we can join list in Python?
7.4.
How do you join a set of strings in Python?
8.
Conclusion
Last Updated: Mar 27, 2024
Easy

Python String join() Method

Author Geetika Dua
0 upvote

Introduction

We know how engaging the language of python is! It is a versatile language that does wonders. Do you know about Join in python? If not, Don't worry. We got you covered!

join in python

Keep reading to learn about Join in Python.

What is Join() in Python?

The first question that may arise in your mind is, what exactly is a join in python?

Join in Python is an inbuilt string function. It is used to join sequence elements separated by a string separator. The job of the merge function is to join the elements of a sequence and makes it a string. 

Syntax: string_name.join()

sample = ('we', 'are’, 'coding', 'ninjas')

# Put any character to join
s = "."
s = s.join(sample)
print(s)
You can also try this code with Online Python Compiler
Run Code
Output

Syntax of Python join() Function

The syntax for the Python join() Function is as follows:

StringSeperator.join(iterable)

Python join() Parameters

Python join() parameter consists of a single parameter,

  • iterable: The iterable can be of any type, including Tuple, List, Set, String, and Dictionary.

Return Value of join() in Python

The return value of join() in Python is of type String. It returns a string after the concatenation of all elements of iterable.

String join() in Python Examples

In this section we will discuss some examples of String join() in Python.

The join() method with sets

  • Python

Python

set_1 = {'Maths', 'Physics', 'Chemistry'}
separator = '+'
print(separator.join(set_1))
You can also try this code with Online Python Compiler
Run Code

Output

output

Explanation

In the above example, set_1 contains the element of a set that are concatenated with “+” which acts as the string separator.

The join() method with dictionaries

  • Python

Python

Dict_1 = {'X': 1, "Y": 2}
separator = '->'
print(separator.join(Dict_1))
You can also try this code with Online Python Compiler
Run Code

Output

output

Explanation

In the above example, the join() method joins the keys with the separator and ignores the values of the dictionary.

Frequently Asked Questions 

What is Join() in Python?

Join in Python is an inbuilt string function. It is used to join sequence elements separated by a string separator. The job of the merge function is to join the elements of a sequence and make it a string. 

What is join and split in Python?

The join () function in Python is used to join all the elements from the iterable and create a string and return the string as an output. Whereas the split() in Python is used to split a string into a list.

How we can join list in Python?

There are multiple operators to join list in Python, some of which are the concatenation operator, extend() method, List comprehension, Naive method, etc.

How do you join a set of strings in Python?

We can join a set of strings in Python with the help of the join() function. This function takes iterable as a parameter, and List is an interable.

Conclusion

This blog covered the Join in python. It introduced the concept of join() function in Python and explained its syntax, Parameters, and Return Value. We hope you are now familiar with this topic of Join in Python. Eager to learn more? Refer to our other blogs-

Happy Coding!

Live masterclass