https:\/\/www.geeksforgeeks.org\/python-string-join-method\/<\/a>.<\/p>Thank you for watching!<\/p>\",\"source\":\"https:\/\/videos.geeksforgeeks.org\/hls\/bfe0c29f71fe7a617499c32723f7e16bgfg-PythonStringjoinMethod20240618150156.m3u8\",\"category\":[{\"term_id__id\":10,\"term_id__term_name\":\"Python\",\"term_id__term_type\":1,\"term_id__slug\":\"python\"},{\"term_id__id\":118,\"term_id__term_name\":\"Python\",\"term_id__term_type\":2,\"term_id__slug\":\"python-eghmaz\"}],\"meta\":{\"thumbnail\":\"https:\/\/media.geeksforgeeks.org\/geeksforgeeks\/PythonStringjoinMethod\/PythonStringjoinMethod20240618150201-small.png\",\"largeThumbnail\":\"https:\/\/media.geeksforgeeks.org\/geeksforgeeks\/PythonStringjoinMethod\/PythonStringjoinMethod20240618150201.png\",\"likes\":0,\"views\":4490,\"isFeatured\":0,\"isPremium\":0,\"isPublic\":0,\"format\":\"video\/mp4\",\"revision\":{}},\"time\":\"18\/06\/2024\",\"subtitle\":\"https:\/\/videos.geeksforgeeks.org\/subtitles\/PythonStringjoinMethod20240618150156.vtt\",\"duration\":579,\"course_link\":null,\"video_schema\":{\"@context\":\"https:\/\/schema.org\",\"@type\":\"VideoObject\",\"name\":\"Python String join() Method\",\"description\":\"Python str.join() MethodIn this video, we will explore the join() method in Python, a powerful and flexible method for concatenating strings. This tutorial is perfect for students, professionals, or anyone interested in enhancing their Python programming skills by learning how to effectively use the join() method.Why Use str.join()?The join() method provides a convenient way to concatenate a list (or any iterable) of strings into a single string with a specified separator. This is especially useful when you need to combine multiple strings into a single string with a specific format.Key Concepts1. str.join() MethodA method that concatenates the elements of an iterable (such as a list or tuple) into a single string, with a specified separator between each element.2. SeparatorThe string that separates each element in the resulting concatenated string.Steps to Use str.join()Step 1 Define an Iterable of StringsCreate a List or TupleDefine a list or tuple containing the strings you want to join.Step 2 Choose a SeparatorDefine a SeparatorDecide on a string to use as the separator between each element (e.g., space, comma, hyphen).Step 3 Use the join() MethodCall join()Call the join() method on the separator string, passing the iterable of strings as an argument.Practical ExamplesExample 1 Joining with a Space SeparatorDescriptionJoin a list of words into a single sentence with spaces between each word.Example 2 Joining with a Comma SeparatorDescriptionJoin a list of items into a single string with commas separating each item.Example 3 Joining with a Custom SeparatorDescriptionJoin a list of strings with a custom separator, such as a hyphen or a slash.Practical ApplicationsSentence ConstructionEasily construct sentences or paragraphs from lists of words or phrases.Data FormattingFormat data into strings for display or output, such as CSV formatting.URL ConstructionCombine URL components into a single URL string with slashes as separators.Additional ResourcesFor more detailed information and a comprehensive guide on the str.join() method in Python, check out the full article on GeeksforGeeks httpswww.geeksforgeeks.orgpython-string-join-method. This article provides in-depth explanations, examples, and further readings to help you master the join() method.By the end of this video, youll have a solid understanding of how to use the str.join() method in Python to concatenate strings efficiently, enhancing your ability to handle and format strings in your projects.Read the full article for more details httpswww.geeksforgeeks.orgpython-string-join-method.Thank you for watching\",\"thumbnailUrl\":[\"https:\/\/media.geeksforgeeks.org\/geeksforgeeks\/PythonStringjoinMethod\/PythonStringjoinMethod20240618150201.png\",\"https:\/\/media.geeksforgeeks.org\/geeksforgeeks\/PythonStringjoinMethod\/PythonStringjoinMethod20240618150201-seo.png\",\"https:\/\/media.geeksforgeeks.org\/geeksforgeeks\/PythonStringjoinMethod\/PythonStringjoinMethod20240618150201-small.png\"],\"uploadDate\":\"2024-06-18T15:05:46Z\",\"duration\":\"PT0H9M39S\",\"contentUrl\":\"https:\/\/www.geeksforgeeks.org\/videos\/python-string-join-method\/\"}}]");
Python String join() Method - GeeksforGeeks
Skip to content
▲
Python String join() Method
Last Updated :
18 Nov, 2025
The join() method is used to combine elements of an iterable into a single string, placing a chosen separator between each element. It works only with iterables containing strings, making it an efficient way to build structured text.
Example 1: This example joins the elements of a tuple using a hyphen (-) as the separator, producing a structured string.
Python
t = ( "Learn" , "Python" , "Fast" )
res = "-" . join ( t )
print ( res )
Explanation: "-".join(t) inserts "-" between each tuple element to form a single string.
Syntax 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 combined string. Raises TypeError if any element is not a string.
Examples Example 2: This example shows how join() handles a set. Since sets are unordered, the output order may vary each time.
Python
s = { "Python" , "is" , "fun" }
res = " " . join ( s )
print ( res )
Note: Since sets are unordered, the resulting string may appear in any order, such as "fun is Python" or "Python is fun", etc.
Example 3: Here, join() is applied to a dictionary. Since iteration over a dictionary defaults to keys, only the keys are joined.
Python
d = { "Geek" : 1 , "for" : 2 , "Geeks" : 3 }
res = "_" . join ( d )
print ( res )
Explanation: "_".join(d) joins dictionary keys because join() reads only the keys during iteration.
Python String join() Method
Explore
Python Fundamentals Python Data Structures Advanced Python Data Science with Python Web Development with Python Python Practice
top_of_element && top_of_screen < bottom_of_element) ||
(bottom_of_screen > articleRecommendedTop && top_of_screen < articleRecommendedBottom) ||
(top_of_screen > articleRecommendedBottom)) {
if (!isfollowingApiCall) {
isfollowingApiCall = true;
setTimeout(function(){
if (loginData && loginData.isLoggedIn) {
if (loginData.userName !== $('#followAuthor').val()) {
is_following();
} else {
$('.profileCard-profile-picture').css('background-color', '#E7E7E7');
}
} else {
$('.follow-btn').removeClass('hideIt');
}
}, 3000);
}
}
});
}
$(".accordion-header").click(function() {
var arrowIcon = $(this).find('.bottom-arrow-icon');
arrowIcon.toggleClass('rotate180');
});
});
window.isReportArticle = false;
function report_article(){
if (!loginData || !loginData.isLoggedIn) {
const loginModalButton = $('.login-modal-btn')
if (loginModalButton.length) {
loginModalButton.click();
}
return;
}
if(!window.isReportArticle){
//to add loader
$('.report-loader').addClass('spinner');
jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', {
PRACTICE_API_URL: practiceAPIURL,
PRACTICE_URL:practiceURL
},function(responseTxt, statusTxt, xhr){
if(statusTxt == "error"){
alert("Error: " + xhr.status + ": " + xhr.statusText);
}
});
}else{
window.scrollTo({ top: 0, behavior: 'smooth' });
$("#report_modal_content").show();
}
}
function closeShareModal() {
const shareOption = document.querySelector('[data-gfg-action="share-article"]');
shareOption.classList.remove("hover_share_menu");
let shareModal = document.querySelector(".hover__share-modal-container");
shareModal && shareModal.remove();
}
function openShareModal() {
closeShareModal(); // Remove existing modal if any
let shareModal = document.querySelector(".three_dot_dropdown_share");
shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" }));
document.querySelector(".hover__share-modal-container").append(
Object.assign(document.createElement('div'), { className: "share__modal" }),
);
document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" }));
const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"];
socialOptions.forEach((socialOption) => {
const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" });
const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` });
const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` });
const shareLink = (socialOption === "Copy Link") ?
Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) :
Object.assign(document.createElement('a'), { className: "link-container" });
if (socialOption === "LinkedIn") {
shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`);
shareLink.setAttribute('target', '_blank');
}
if (socialOption === "WhatsApp") {
shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`);
shareLink.setAttribute('target', "_blank");
}
if (socialOption === "Twitter") {
shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`);
shareLink.setAttribute('target', "_blank");
}
shareLink.append(icon, socialText);
socialContainer.append(shareLink);
document.querySelector(".share__modal").appendChild(socialContainer);
//adding copy url functionality
if(socialOption === "Copy Link") {
shareLink.addEventListener("click", function() {
var tempInput = document.createElement("input");
tempInput.value = window.location.href;
document.body.appendChild(tempInput);
tempInput.select();
tempInput.setSelectionRange(0, 99999); // For mobile devices
document.execCommand('copy');
document.body.removeChild(tempInput);
this.querySelector(".share__option-text").textContent = "Copied"
})
}
});
// document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu"));
}
function toggleLikeElementVisibility(selector, show) {
document.querySelector(`.${selector}`).style.display = show ? "block" : "none";
}
function closeKebabMenu(){
document.getElementById("myDropdown").classList.toggle("show");
}
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
min 4 words, max Words Limit:1000
Thank You!
Your suggestions are valuable to us.