Python-Ref > String manipulation > String splitting and joining > Join on other types than lists
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Join on other types than lists

The string join method may be used on other sequence types.
In the same way as with lists the join method may be used for tuples...
Expand/Shrink
  1   words = ("First","second","third")  # tuple of strings
  2   
  3   print ' '.join( words)
  4   print '-'.join( words)
  5   print ' -- very long delimiter -- '.join( words)
stdout:
First second third
First-second-third
First -- very long delimiter -- second -- very long delimiter -- third
Doba běhu: 13.7 ms
... or even strings, because they are also of sequence type.
Expand/Shrink
  1   text = "Hello World, I am here."
  2   
  3   print '*'.join( text)
  4   print '   '.join( text)
  5   print ''.join( text)  # this should not change the string
stdout:
H*e*l*l*o* *W*o*r*l*d*,* *I* *a*m* *h*e*r*e*.
H   e   l   l   o       W   o   r   l   d   ,       I       a   m       h   e   r   e   .
Hello World, I am here.
Doba běhu: 13.6 ms