Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
String lower() Method in Python
Next article icon

Python String join() Method

Last Updated : 12 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The join() method in Python is used to concatenate the elements of an iterable (such as a list, tuple, or set) into a single string with a specified delimiter placed between each element.

Lets take a simple example to join list of string using join() method.

Joining a List of Strings

In below example, we use join() method to combine a list of strings into a single string with each string separated by a space.

Python
a = ['Hello', 'world', 'from', 'Python'] res = ' '.join(a) print(res)   

Output
Hello world from Python 

Table of Content

  • Syntax of join()
  • Examples of join() Method on Different Data Types
    • Using join() with Tuples
    • Using join() with set
    • Using join() with Dictionary
  • Frequently Asked Questions on Python String Join() Method

Syntax of join()

separator.join(iterable)

Parameters:

  • separator: The string placed between elements of the iterable.
  • iterable: A sequence of strings (e.g., list, tuple etc) to join together.

Return Value:

  • Returns a single string formed by joining all elements in the iterable, separated by the specified separator
  • If the iterable contains any non-string values and it raises a TypeError exception.

Examples of join() Method on Different Data Types

Below are examples of how join() method works with different data types.

Using join() with Tuples

The join() method works with any iterable containing strings, including tuples.

Python
s = ("Learn", "to", "code")  # Separator "-" is used to join strings res = "-".join(s) print(res) 

Output
Learn-to-code 

Using join() with set

In this example, we are joining set of String.

Python
s = {'Python', 'is', 'fun'}  # Separator "-" is used to join strings res = '-'.join(s) print(res)  

Output
Python-is-fun 

Note: Since sets are unordered, the resulting string may appear in any order, such as “fun is Python” or “Python is fun”.

Using join() with Dictionary

When using the join() method with a dictionary, it will only join the keys, not the values. This is because join() operates on iterables of strings and the default iteration over a dictionary returns its keys.

Python
d = {'Geek': 1, 'for': 2, 'Geeks': 3}  # Separator "_" is used to join keys into a single string res = '_'.join(d)  print(res) 

Output
Geek_for_Geeks 


Next Article
String lower() Method in Python

S

Striver
Improve
Article Tags :
  • Python
  • Python-Functions
  • python-list
  • python-string
Practice Tags :
  • python
  • python-functions
  • python-list

Similar Reads

  • Python String format_map() Method
    Python String format_map() method is an inbuilt function in Python, which is used to return a dictionary key's value. Syntax: string.format_map(z) Parameters: Here z is a variable in which the input dictionary is stored and string is the key of the input dictionary. input_dict: Takes a single parame
    2 min read
  • Python String index() Method
    The index() method in Python is used to find the position of a specified substring within a given string. It is similar to the find() method but raises a ValueError if the substring is not found, while find() returns -1. This can be helpful when we want to ensure that the substring exists in the str
    2 min read
  • Python String isalnum() Method
    The isalnum() method is a string function in Python that checks if all characters in the given string are alphanumeric. If every character is either a letter or a number, isalnum() returns True. Otherwise, it returns False. For Example: [GFGTABS] Python s = "Python123" res = s.isalnum() pr
    2 min read
  • Python String isalpha() Method
    The isalpha() method checks if all characters in a given string are alphabetic. It returns True if every character in the string is a letter and False if the string contains any numbers, spaces, or special characters. Let’s start with a simple example of using isalpha() [GFGTABS] Python s1 = "H
    2 min read
  • Python string isdecimal() Method
    In Python, the isdecimal() method is a quick and easy way to check if a string contains only decimal digits. It works by returning True when the string consists of digits from 0 to 9 and False otherwise. This method is especially useful when we want to ensure that user inputs or string data are stri
    3 min read
  • Python String isdigit() Method
    The isdigit() method is a built-in Python function that checks if all characters in a string are digits. This method returns True if each character in the string is a numeric digit (0-9) and False otherwise. Example: [GFGTABS] Python a = "12345" print(a.isdigit()) b = "1234a5" pr
    3 min read
  • Python String isidentifier() Method
    The isidentifier() method in Python is used to check whether a given string qualifies as a valid identifier according to the Python language rules. Identifiers are names used to identify variables, functions, classes, and other objects. A valid identifier must begin with a letter (A-Z or a-z) or an
    3 min read
  • Python String islower() Method
    The islower() method in Python checks if all characters in a string are lowercase. It returns True if all alphabetic characters are lowercase, otherwise, it returns False, if there is at least one uppercase letter. Let's look at a quick example of using the islower() method. [GFGTABS] Python s =
    2 min read
  • Python String isnumeric() Method
    The isnumeric() method is a built-in method in Python that belongs to the string class. It is used to determine whether the string consists of numeric characters or not. It returns a Boolean value. If all characters in the string are numeric and it is not empty, it returns “True” If all characters i
    3 min read
  • Python String isprintable() Method
    Python String isprintable() is a built-in method used for string handling. The isprintable() method returns "True" if all characters in the string are printable or the string is empty, Otherwise, It returns "False". This function is used to check if the argument contains any printable characters suc
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences