Python-Ref > String manipulation > String splitting and joining > String splitting
 
 

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

String splitting

Introduces basic string method split.
One of the common tasks performed with strings is their splitting. Most usually you want to split sentences into words as in the following example.
Expand/Shrink
  1   text = "Hello World, I am here."
  2   
  3   print text.split()  # the split method can be used to split a string to words
  4   print text.split(" ")   # it is also possible to give split method an character that is used as delimiter
  5   print text.split(",")
  6   print text.split("l")   # the delimiter is lost in the process 
stdout:
['Hello', 'World,', 'I', 'am', 'here.']
['Hello', 'World,', 'I', 'am', 'here.']
['Hello World', ' I am here.']
['He', '', 'o Wor', 'd, I am here.']
Doba běhu: 13.6 ms
The split method takes the delimiter as the first argument or uses any whitespace character in case the argument is ommited.