Overview
This post will show some examples of the Python join method.
What is important to remember is that the character that joins the elements
is the one upon which the function is called.
Join Examples
Let’s show an example
Creating a new list
>>> music = ["Abba","Rolling Stones","Black Sabbath","Metallica"]
>>> print music
['Abba', 'Rolling Stones', 'Black Sabbath', 'Metallica']
Join a list with an empty space
>>> print ' '.join(music)
Abba Rolling Stones Black Sabbath Metallica
Join a list with a new line
>>> print "
".join(music)
Abba
Rolling Stones
Black Sabbath
Metallica
Join a list with a tab
>>> print " ".join(music)
Abba Rolling Stones Black Sabbath Metallica
>>>
Happy scripting!
Recommended Python Training
Course: Python 3 For Beginners
Over 15 hours of video content with guided instruction for beginners. Learn how to create real world applications and master the basics.