How to split a string at the last occurrence of a separator in Python

1 Answer

0 votes
s = "python c++ c c# java"

part_before, separator, part_after = s.rpartition('c')

print("part_before = " + part_before)
print("separator = " + separator)
print("part_after = " + part_after)


'''
run:

part_before = python c++ c
separator = c
part_after = # java

'''

 



answered Feb 25, 2017 by avibootz

Related questions

...