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 & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.