0

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 :)

2 Answers2

0

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']
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97
0

You can use the split() method. It returns a list of words in a string that are separated by the delimiter that you passed in as the parameter.

result = 'hello world'.split(' ')
result
['hello', 'world']
greginvm
  • 245
  • 2
  • 5