Python Join Examples

来源:互联网 发布:黑马程序员找不到工作 编辑:程序博客网 时间:2024/05/21 08:00

原文链接:点我

Overview

This post will show some examples of the Python join method. What is important to remember is that the character that joins the elementsis 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 "\n".join(music)AbbaRolling StonesBlack SabbathMetallica
Join a list with a tab
>>> print "\t".join(music)AbbaRolling StonesBlack SabbathMetallica>>> 
Happy scripting!

0 0
原创粉丝点击