User Tools

Site Tools


python:join

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

python:join [2013/03/16 17:41] (current)
Line 1: Line 1:
 +=== How to use join to merge substrings into a string ===
  
 +
 +If you have one list of strings, for example list = ["​orange",​ "​banana",​ "​apple"​] and you want them into a single string, just use **join** :
 +
 +<code python>
 +>>>​ list = ["​orange",​ "​banana",​ "​apple"​]
 +>>>​ print list
 +['​orange',​ '​banana',​ '​apple'​]
 +>>>​ str = ";"​.join(list)
 +>>>​ print str
 +orange;​banana;​apple
 +>>>​
 +>>>​ str = "​_"​.join(list)
 +>>>​ print str
 +orange_banana_apple
 +>>>​
 +>>>​ str = "​XXX"​.join(list)
 +>>>​ print str
 +orangeXXXbananaXXXapple
 +
 +</​code>​
python/join.txt ยท Last modified: 2013/03/16 17:41 (external edit)