+ 12
What is the best way to split a string in Python?
3 Respostas
+ 1
Alternatively, you can use the split method from the re module if you want to split by regular expressions:
import re
pattern = '\s?\+\s?' # a plus sign between 0, 1 spaces from left and right
string = '1 +2 + 3+ 4+5'
re.split(pattern, string)
>>> ['1', '2', '3', '4', '5']
0
print("python is the best of /n all
result:python is the best of
all