I used split()
and rsplit()
as shown below:
test = "1--2--3--4--5"
print(test.split("--")) # Here
print(test.rsplit("--")) # Here
Then, I got the same result as shown below:
['1', '2', '3', '4', '5'] # split()
['1', '2', '3', '4', '5'] # rsplit()
So, what's the difference between split()
and rsplit()
?
test = "1--2--3--4--5"
print(test.split("--", 2)) # Here
print(test.rsplit("--", 2)) # Here
Output:
['1', '2', '3--4--5'] # split()
['1--2--3', '4', '5'] # rsplit()
In addition, if split()
and rsplit()
have no arguments as shown below:
test = "1 2 3 4 5"
print(test.split()) # No arguments
print(test.rsplit()) # No arguments
They can divide a string by one or more spaces as shown below:
['1', '2', '3', '4', '5'] # split()
['1', '2', '3', '4', '5'] # rsplit()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With