Python Join String Method

Publicado em: 30 Setembro 2015
no canal de: Code master
12,302
132

Be sure to like, share and comment to show your support for our tutorials.

=======================================
Channel - https://goo.gl/pnKLqE
Playlist For This Tutorial - https://goo.gl/EyZFti
Latest Video - https://goo.gl/atWRkF
Facebook -   / mastercodeonline  
Twitter - https://twitter.com/mastercodeonlin?l...
Website - http://mastercode.online
======================================
Python Join String Method
In this Python tutorial, we are going to focus on the Python join string method. This string method enables us to join strings together and allows us to provide a separator. The join string method will take the string object in which is called on as the separator and the argument for the string method will concatenated on to the string separator. The join string method only takes one argument so we can iterate through one string object or multiple string objects but we need to place our string objects in a list or tuple so we can iterate through the objects.

Python Join String Method Syntax
'separator'.join(['Strings', 'to', 'concatenate'])

'Separator' - The separator will be placed in between each string object in the join argument.
.join(['Strings', 'to', 'concatenate']) - The string objects contained in a list in the argument will be concatenated on the each other using the string object separator.
Examples of The Python Join String Method
#Example 1
' '.join(['This', 'is', 'a', 'string'])
'This is a string'

#Example 2
' '.join(('This', 'is', 'a', 'string'))
'This is a string'

#Example 3
' - '.join('Mississippi')
'M - i - s - s - i - s - s - i - p - p - i'
Examples Explained

Example 1:

' '.join(['This', 'is', 'a', 'string']) - We create a string object containing a space and then we call the join string method on our string object. The join string method contains a argument of a list that contains four string objects that we would like to combine and separate by a space.

'This is a string' - We are returned a string. The string is made up of the string objects from our list and separated by our original string object.

Example 2:

' '.join(('This', 'is', 'a', 'string')) - We create a string that contains a space and call the string method of join on our string object. Our join string method contains an argument that contains a tuple which contains four string objects.

'This is a string' - We are returned a string like above that separates the string objects contained in the tuple.

Example 3:

' - '.join('Mississippi') - We create a string object that contains a space then hyphen the space to be the separator and then we call the join string method on our string object that contains a string object.

'M - i - s - s - i - s - s - i - p - p - i' - We are returned a new string object where each character is separated by a space then a hyphen and then another space.

Conclusion

In this Python tutorial we looked the Python join string method which can be used to concatenate strings. If you have any questions about the join string method leave a comment below.


Nesta página do site você pode assistir ao vídeo on-line Python Join String Method duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Code master 30 Setembro 2015, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 12,302 vezes e gostou 132 espectadores. Boa visualização!