Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python String join() Method

  • Difficulty Level : Basic
  • Last Updated : 19 Aug, 2021

Python String join() method is a string method and returns a string in which the elements of the sequence have been joined by the str separator.

Syntax: 

string_name.join(iterable) 

Parameters: 

The join() method takes iterable – objects capable of returning their members one at a time. Some examples are List, Tuple, String, Dictionary, and Set

Return Value: 

The join() method returns a string concatenated with the elements of iterable

Type Error:

If the iterable contains any non-string values, it raises a TypeError exception. 

Example 1: Working of join() method

Python




# Python program to demonstrate the
# use of join function to join list
# elements with a character.
  
list1 = ['1','2','3','4'
  
s = "-"
  
# joins elements of list1 by '-'
# and stores in sting s
s = s.join(list1)
  
# join use to join a list of
# strings to a separator s
print(s)


Output: 

1-2-3-4

Example 2: Joining with an empty string

Python




# Python program to demonstrate the
# use of join function to join list
# elements without any separator.
  
# Joining with empty separator
list1 = ['g','e','e','k', 's'
print("".join(list1))


Output: 

geeks

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!