• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Python » Python String join() Method
Next →
← Prev

Python String join() Method

By Dinesh Thakur

The join() method is used to join separator items to the input string. It accepts as parameters iterables such as collection, list, tuple, string, etc., and another string.

The join() function returns a string that joins the iterable elements to the separator string passed on to the function as an argument.

The syntax of the method is: str.join(sequence)

Key Points :

• Every string will concatenate flexibly with this join() method.
• This function would concatenate any single element of an iterable (such as an array, tuple, dictionary, array, etc.) with a string and results in a concatenated string.
• When there is a non-string is an iterable, the exception to TypeError raise.
• The method used to return the string in which the sequence elements join with the string separator is Python String join().

We’ll be covering the following topics in this tutorial:

  • Parameters for the join() method
  • Python String join(): Return Value
  • The join() method with sets
  • Python String join() when Set is used as an iterable

Parameters for the join() method

The join() method uses an iterable parameter (objects that can return their members one by one).

Some of the example of iterables are:

• Native data types – List, Tuple, String, Dictionary and Set.

Python String join(): Return Value

• If there are non-string values in an iterable, the exception for TypeError is raised.
• If a dictionary is used as an iterable, the values retrieved are the keys and not the values.
• If there are string values returned as a result in an iterable concatenated string.

Below is the python program to demonstrate the join() function:

str = " - ";
seq = ("Computer", "Notes"); # This is sequence of strings.
print (str.join( seq ))

When we run above the program, the outcome is as follows:

Computer – Notes

The join() method with sets

# .join() with sets
str= {'2', '1', '3'}
s = ', '
print(s.join(str))
test = {'Beta', 'Alpha', 'Gamma'}
s = '-'
print(s.join(str))

When we run above the program, the outcome is as follows:

1, 2, 3
1-2-3

Note: A set is a selection of unordered objects, so that you can have different output (order is random).

Python String join() when Set is used as an iterable

In the following python script, we tried to use the join() function with a set (a list of unordered and unindexed elements) as an iterable:

str = {'10', '20', '30'}
sep = ', '
print(sep.join(str))

When we run above the program, the outcome is as follows:

30, 10, 20

In the above example, we have used a set and join them with a separator , .As set is unordered so you will see elements in a different order in the output. The output for the same is given below:

Python Remove Character from String using join() Method

str = "mama786papa" 
res_str = ''.join([str[i] for i in range(len(str)) if i != 2]) 
print (res_str)

When we run above the program, the outcome is as follows:

maa786papa

Below are several other functions that we can use to work with string in Python 3

capitalize()
center()
count()
decode()
encode()
endswith()
expandtabs()
find()
index()
isalnum()

isalpha()

isdecimal()
isdigit()
islower()
isnumeric()
isspace()
istitle()
isupper()
join()
ljust()

lower()

lstrip()
maketrans()
max()
min()
replace()
rfind()
rindex()
rjust()
rstrip()

split()

splitlines()
startswith()
strip()
swapcase()
title()
translate()
upper()
zfill()

You’ll also like:

  1. Python String maketrans() Method
  2. Python String replace() Method
  3. Python String ljust() Method
  4. Python String isdigit() Method
  5. Python String count() Method
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Python

Python Tutorials

  • Python - Home
  • Python - Features
  • Python - Installation
  • Python - Hello World
  • Python - Operators Types
  • Python - Data Types
  • Python - Variable Type
  • Python - Switch Case
  • Python - Line Structure
  • Python - String Variables
  • Python - Condition Statement
  • Python - if else Statement
  • Python - for-loop
  • Python - while loop
  • Python - Command Line
  • Python - Regular Expression

Python Collections Data Types

  • Python - List
  • Python - Sets
  • Python - Tuples
  • Python - Dictionary

Python Functions

  • Python - Functions
  • Python - String Functions
  • Python - Lambda Function
  • Python - map() Function

Python Object Oriented

  • Python - Oops Concepts
  • Python - File Handling
  • Python - Exception Handling
  • Python - Multithreading
  • Python - File I/O

Python Data Structure

  • Python - Linked List
  • Python - Bubble Sort
  • Python - Selection Sort
  • Python - Linear Search
  • Python - Binary Search

Python Programs

  • Python - Armstrong Number
  • Python - Leap Year Program
  • Python - Fibonacci Series
  • Python - Factorial Program

Other Links

  • Python - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW