Join Category Page - PythonForBeginners.com https://www.pythonforbeginners.com Learn By Example Thu, 27 Aug 2020 18:06:32 +0000 en-US hourly 1 https://wordpress.org/?v=5.8.13 https://www.pythonforbeginners.com/wp-content/uploads/2020/05/cropped-pfb_icon-32x32.png Join Category Page - PythonForBeginners.com https://www.pythonforbeginners.com 32 32 201782279 Python Join Examples https://www.pythonforbeginners.com/code-snippets-source-code/python-join-examples Thu, 20 Sep 2012 07:35:41 +0000 https://www.pythonforbeginners.com/?p=451 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 […]

The post Python Join Examples appeared first on PythonForBeginners.com.

]]>
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!

The post Python Join Examples appeared first on PythonForBeginners.com.

]]>
451