rpartition()

partition() returns a three element tuple by breaking the string using input search string. Three parts are here.

1. Left part of the matched string
2. The searched string
3. Right part of the matched string
my_str='Welcome to Plus2net'
output=my_str.rpartition('to')
print(output)
Output is here
('Welcome ', 'to', ' Plus2net')
We can add one more line to display the last element
print(output[2])
Output
  plus2net
If matching string is not found then rpartition() returns the tuple with 3rd element as full string.
my_str='Welcome to Plus2net'
output=my_str.rpartition('ab')
print(output)
Output is here
('', '', 'Welcome to Plus2net')
If we use partition() in place or rpartition() the output is here ( the difference between rpartition() and partition() )
('Welcome to Plus2net', '', '')
All String methods



plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer