Join Function in Python

Last updated by Vartika Rai on Sep 25, 2025 at 03:43 PM
| Reading Time: 3 minutes

Software developers deal with strings frequently. Given that, the more flexibility a language can provide for dealing with strings, the easier it will become to create and manipulate strings the way they need to as per our requirements.

One method in Python that serves this need by helping us create and concatenate strings flexibly is the join method, which we’ll discuss in this article.

We’ll learn:

  • What Is the join() Function in Python?
  • Uses of join() in Python
  • Join Function Example — Code and Output
  • FAQs

What Is the join() Function in Python?

The string method join() is a built-in function in Python that provides flexibility in creating and concatenating strings in Python from an iterable.

  • Parameter: Iterables are objects we can iterate over and return them one at a time. The join() function takes an iterable containing string type elements, like some sequence or a collection of strings represented as a list, string, array, tuple, dictionary, etc., as its parameter.
  • Is Called On: The join() function is called on a string separator, which represents the separator the elements in the provided iterable will be concatenated using.
  • Returns: It returns a string that concatenates the elements in the iterable, which are separated by the provided string separator.
  • TypeError: The join() method takes iterable containing values that only belong to the string data type. In case any non-string value is present in the iterable, we’ll get a TypeError.

Syntax:

stringseparator.join(iterable)

Note that the join() method takes the whole iterable as an argument, i.e., the join method concatenates each element present in the iterable using the separator string. We can’t selectively choose elements to concatenate.

Uses of join() in Python

  • We can create strings from iterable objects using join().
  • It helps us concatenate all the elements in an iterable using any preferred separator.
  • We can use it to perform a lot of tasks like:
    1. Combining a list of words into a sentence
    2. Separating a set of steps for a task using an arrow sign
    3. Combining a list of characters into a word by using an empty string as the separator
  • For a long list, adding a symbol after every element as a separator would be time taking and wasteful, and join removes the need for us to manually do that.

Join Function Example

Let us now understand this through an example using the join function in Python3. Here, we’ve taken different types of iterables containing string data: sequences like a list, a tuple, etc., and collections like a dictionary and joined them using different types of separators.

Code

listEx = [‘Interview’, ‘Kickstart’]

setEx = {‘4’, ‘8’, ‘3’, ‘2’}

 

tupleEx = (‘Congrats’,’ That is amazing’,’ I can not believe it’,”)

tupleEx2 = (‘Congrats’,’ That is amazing’,’ I can not believe it’)

 

dictionaryEx = {‘One’:1,’Two’:2, ‘Three’:3}

 

separatorSpace =’ ‘

separatorExclamation =’!’

separatorThen =’ then ‘

separatorArrow = ‘–>’

 

print(separatorSpace.join(listEx))

print(separatorExclamation.join(tupleEx))

print(separatorExclamation.join(tupleEx2))

print(separatorThen.join(dictionaryEx))

print(separatorArrow.join(setEx))

Output

Interview Kickstart

Congrats! That is amazing! I can not believe it!

Congrats! That is amazing! I can not believe it

One then Three then Two

8–>4–>3–>2

A few things to note here:

  • The dictionary’s key needs to be a string, but the value stored inside the key can be of another type, and we won’t get a TypeError.
  • It is NOT that the addition of one separator occurs after adding each element. A separator concatenates two elements.
  • And so, as in the case of the exclamation mark (!), the last element will not have a separator after it by default. We must add the separator separately at the end. We can also add an empty string as an additional element in the list that’s then concatenated using the separator at the end.

FAQs

Question 1: If a dictionary has integer type keys and string type values, can we concatenate the values using the join() function?

Yes, we need to just put values as the iterable to achieve this. Here’s how that can be done:

dictionaryEx = {1:’One’,2:’Two’, 3: ‘Three’}

separatorThen =’ then ‘

print(separatorThen.join(dictionaryEx.values()))

 

Output:

One then Two then Three

Question 2: If a dictionary has integer type keys and string type values, what happens if we attempt concatenating the keys using the join() function?

We can’t concatenate keys of integer type using the join function. If we try to do that, we’ll get a TypeError, as can be seen here:

dictionaryEx = {1:’One’,2:’Two’, 3: ‘Three’}

separatorThen =’ then ‘

print(separatorThen.join(dictionaryEx))

Output:

stderr

Traceback (most recent call last):

File “./file_name.py”, line 3, in <module>

TypeError: sequence item 0: expected str instance, int found

Recommended Reading

Are you a software engineer looking for coding interview questions to aid your interview prep? Check out these useful pages for software developers:

Are You Ready to Nail Your Next Coding Interview?

Whether you’re a Coding Engineer gunning for Software Developer or Software Engineer roles, or you’re targeting management positions at top companies, IK offers courses specifically designed for your needs to help you with your technical interview preparation!

If you’re looking for guidance and help with getting started, sign up for our free webinar. As pioneers in the field of technical interview prep, we have trained thousands of Software Engineers to crack the most challenging coding interviews and land jobs at their dream companies, such as Google, Facebook, Apple, Netflix, Amazon, and more!

Sign up now!

————

Article contributed by Tanya Shrivastava

Last updated on: September 25, 2025
Register for our webinar

Uplevel your career with AI/ML/GenAI

Loading_icon
Loading...
1 Enter details
2 Select webinar slot
By sharing your contact details, you agree to our privacy policy.

Select a Date

Time slots

Time Zone:

Strange Tier-1 Neural “Power Patterns” Used By 20,013 FAANG Engineers To Ace Big Tech Interviews

100% Free — No credit card needed.

Register for our webinar

Uplevel your career with AI/ML/GenAI

Loading_icon
Loading...
1 Enter details
2 Select webinar slot
By sharing your contact details, you agree to our privacy policy.

Select a Date

Time slots

Time Zone:

IK courses Recommended

Land high-paying DE jobs by enrolling in the most comprehensive DE Interview Prep Course taught by FAANG+ engineers.

Fast filling course!

Ace the toughest backend interviews with this focused & structured Backend Interview Prep course taught by FAANG+ engineers.

Elevate your engineering career with this interview prep program designed for software engineers with less than 3 years of experience.

Ready to Enroll?

Get your enrollment process started by registering for a Pre-enrollment Webinar with one of our Founders.

Next webinar starts in

00
DAYS
:
00
HR
:
00
MINS
:
00
SEC

Register for our webinar

How to Nail your next Technical Interview

Loading_icon
Loading...
1 Enter details
2 Select slot
By sharing your contact details, you agree to our privacy policy.

Select a Date

Time slots

Time Zone:

Almost there...
Share your details for a personalised FAANG career consultation!
Your preferred slot for consultation * Required
Get your Resume reviewed * Max size: 4MB
Only the top 2% make it—get your resume FAANG-ready!

Registration completed!

🗓️ Friday, 18th April, 6 PM

Your Webinar slot

Mornings, 8-10 AM

Our Program Advisor will call you at this time

Register for our webinar

Transform Your Tech Career with AI Excellence

Transform Your Tech Career with AI Excellence

Join 25,000+ tech professionals who’ve accelerated their careers with cutting-edge AI skills

25,000+ Professionals Trained

₹23 LPA Average Hike 60% Average Hike

600+ MAANG+ Instructors

Webinar Slot Blocked

Interview Kickstart Logo

Register for our webinar

Transform your tech career

Transform your tech career

Learn about hiring processes, interview strategies. Find the best course for you.

Loading_icon
Loading...
*Invalid Phone Number

Used to send reminder for webinar

By sharing your contact details, you agree to our privacy policy.
Choose a slot

Time Zone: Asia/Kolkata

Choose a slot

Time Zone: Asia/Kolkata

Build AI/ML Skills & Interview Readiness to Become a Top 1% Tech Pro

Hands-on AI/ML learning + interview prep to help you win

Switch to ML: Become an ML-powered Tech Pro

Explore your personalized path to AI/ML/Gen AI success

Your preferred slot for consultation * Required
Get your Resume reviewed * Max size: 4MB
Only the top 2% make it—get your resume FAANG-ready!
Registration completed!
🗓️ Friday, 18th April, 6 PM
Your Webinar slot
Mornings, 8-10 AM
Our Program Advisor will call you at this time

Get tech interview-ready to navigate a tough job market

Best suitable for: Software Professionals with 5+ years of exprerience
Register for our FREE Webinar

Next webinar starts in

00
DAYS
:
00
HR
:
00
MINS
:
00
SEC

Your PDF Is One Step Away!

The 11 Neural “Power Patterns” For Solving Any FAANG Interview Problem 12.5X Faster Than 99.8% OF Applicants

The 2 “Magic Questions” That Reveal Whether You’re Good Enough To Receive A Lucrative Big Tech Offer

The “Instant Income Multiplier” That 2-3X’s Your Current Tech Salary