Break a string into three parts using the input search string ( search_char)
my_str.partition(search_char)
search_char: Used to search the input string my_str
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.partition('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 search string is not found then input string is returned as first element of the tuple and rest two elements will be blank.
my_str='Welcome to Plus2net'
output=my_str.partition('*')
print(output)
Output
('Welcome to Plus2net', '', '')
By using partition() method you can separate domain part and userid part of an email address.