In this article, you will learn about the Python string join() method along with some examples. join function in Python is used to join items of iterable in one string and return a new string.
In the previous tutorial, we have seen the Python string istitle() method to check each word string start with an uppercase letter or not.
Python string join() method
Python join string method is used to concat a string with an iterable object.join() method return the new string which is a concatenation of the string in iterable.
It throws an exception TypeError if iterable contains any non-string value.
The syntax of join function in Python is:-
join function in python takes parameter like string, list, tuple etc.
Python string join method returns a new string which is the concatenation of string in an iterable.
Python string join example
Here we will take some example to understand Python string join method.
str1 = ' ' a = ['Programming', 'Funda'] result = str1.join(a) print(result)
Output will be:- Programming Funda
str1 = ':' a = ['p','r','o','g','r','a','m','m','i','n','g'] result = str1.join(a) print(result)
Output will be:- p:r:o:g:r:a:m:m:i:n:g
string = "-" mystr = ("Programming", "Funda", "is", "the", "best") result = string.join(mystr) print(result)
Output will be:- Programming-Funda-is-the-best
In this tutorial, you have learned the Python string join() method to join all items in an iterable into one string. This is the most useful string method. You can join all the items in an iterable into one string with a specific separator.
I hope this tutorial will have helped you. If you like this article, please share it with your friends who want to learn Python programming.
- String endswith() method
- String casefold() method
- String center() method
- String capitalize() method
- String count() method
- String index() method
- String format() method
- String isalpha() method
- String isidentifier() method
- String islower() method
- String isupper() method
For More Information:- Click Here