I have read the documentation but don’t fully understand how to do it.
I understand that I need to have some kind of identifier in the string so that the functions can find where to split the string (unless I can target the first space in the sentence?).
So for example how would I split:
"Sico87 is an awful python developer" to "Sico87" and "is an awful Python developer"?
The strings are retrieved from a database (if this does matter).
Use
partition(' ')which always returns three items in the tuple – the first bit up until the separator, the separator, and then the bits after. Slots in the tuple that have are not applicable are still there, just set to be empty strings.Examples:
"Sico87 is an awful python developer".partition(' ')returns["Sico87"," ","is an awful python developer"]"Sico87 is an awful python developer".partition(' ')[0]returns"Sico87"An alternative, trickier way is to use
split(' ',1)which works similiarly but returns a variable number of items. It will return a tuple of one or two items, the first item being the first word up until the delimiter and the second being the rest of the string (if there is any).