See these examples
text = 'Essa, é, uma, string, de, teste'
rs1 = text.rsplit(',',1)
rs1
['Essa, é, uma, string, de', ' teste']
rs2 = text.rsplit(',',2)
rs2
['Essa, é, uma, string', ' de', ' teste']
rs_1 = text.rsplit(',',-1)
rs_1
['Essa', ' é', ' uma', ' string', ' de', ' teste']
The difference between split and rsplit is that the "signature" of rsplit accepts the parameter, max
, that is, the maximum number of splits to be made, then the syntax is split(separador, max)
, if max=-1
( default) all possible splits will be made. Conclusion: If you use string.rsplit()
without the max
parameter, the result will be the same as string.split()
.