Token splitting and delimiter joining. : Join « String « Python Tutorial






# splitting strings
string1 = "A, B, C, D, E, F"

print "String is:", string1
print "Split string by spaces:", string1.split()
print "Split string by commas:", string1.split( "," )
print "Split string by commas, max 2:", string1.split( ",", 2 )
print

# joining strings
list1 =  [ "A", "B", "C", "D", "E", "F" ]
string2 = "___"

print "List is:", list1
print 'Joining with "%s": %s' \
   % ( string2, string2.join ( list1 ) )
print 'Joining with "-.-":', "-.-".join( list1 )








5.12.Join
5.12.1.Convert a list of characters back to a string
5.12.2.Joining Strings
5.12.3.Joining a list of words
5.12.4.Token splitting and delimiter joining.