Python split string into multiple string [duplicate]

Solution 1:

You can split a string by using split(). The syntax is as follows...

stringtosplit.split('whattosplitat')

To split your example at every comma and space, it would be:

s = 'str1, str2, str3, str4'
s.split(', ')

Solution 2:

A bit of google would have found this..

string = 'the quick brown fox'
splitString = string.split()

...

['the','quick','brown','fox']

Solution 3:

Try:

s = 'str1, str2, str3, str4'
print s.split(',')