my_str.rsplit(delimiter,max_value)
delimiter : to be used to break the stringmax_value : optional , the number of elements in output plus one. Default value is -1 so it includes all occurance.
my_list="'Alex','Ronald','John'"
my_list=my_list.rsplit(',')
print(my_list)
output
["'Alex'", "'Ronald'", "'John'"]
Without delimiter
my_list="'Alex','Ronald','John'"
my_list=my_list.rsplit()
print(my_list)
["'Alex','Ronald','John'"]
If delimiter is not found
my_list="'Alex','Ronald','John'"
my_list=my_list.rsplit('*')
print(my_list)
Output
["'Alex','Ronald','John'"]
Using one email address to separate domain and userid part
my_list="userid@example.com"
my_list=my_list.rsplit('@')
print(my_list)
Output
['userid', 'example.com']
my_str='Welcome to plus2net'
print(my_str.rsplit('e')) # without any max_value
print(my_str.rsplit('e',2))
print(my_str.split('e',2))
Output
['W', 'lcom', ' to plus2n', 't']
['Welcom', ' to plus2n', 't']
['W', 'lcom', ' to plus2net']
All String methods
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.