Source Code:
(back to article)
string = 'Hello, world!' substring = 'world!' # Split the string using the substring as the delimiter parts = string.rsplit(substring, 1) # Join the parts back together, omitting the substring result = ''.join(parts) print(result) # Output: 'Hello, '
Result:
Report an issue