The list element join method join usage instance in python
- 2020-05-07 19:53:55
- OfStack
This article illustrates the use of the list element join method join in python. Share with you for your reference. Specific analysis is as follows:
Create a list:
>>> music = ["Abba","Rolling Stones","Black Sabbath","Metallica"]
>>> print music
Output:
['Abba', 'Rolling Stones', 'Black Sabbath', 'Metallica']
Join the elements in the list with Spaces through the join function:
>>> print ' '.join(music)
Returns the result
Abba Rolling Stones Black Sabbath Metallica
Link the list with a newline character
>>> print "\n".join(music)
The output
Abba
Rolling Stones
Black Sabbath
Metallica
Use tab symbols to join all elements of the list
>>> print "\t".join(music)
The output
Abba Rolling Stones Black Sabbath Metallica
I hope this article has been helpful to your Python programming.