how would I write this:
string = 'hello world'
string = something
string
[hello, world]
please note that im a beginner and will aperciate a noob friendly explantions :)
how would I write this:
string = 'hello world'
string = something
string
[hello, world]
please note that im a beginner and will aperciate a noob friendly explantions :)
You can use the split()
string method to split a string based on a given delimiter. Omitting a delimiter splits the string on any whitespace.
>>> string = 'hello \t\n world'
>>> string
'hello \t\n world'
>>> split_string = string.split()
>>> split_string
['hello', 'world']
>>> more_string = 'hello<NEWWORD>world'
>>> split_more = more_string.split('<NEWWORD>')
>>> split_more
['hello', 'world']