Python split string into multiple string [duplicate]

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(', ')

Leave a Comment