partition()

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.
my_str='userid@example.com'
output=my_str.partition('@')
print(output)

print('Userid :',output[0])
print('Domain :',output[2])
Output
('userid', '@', 'example.com')
Userid : userid
Domain : example.com
All String methods


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate 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.



Subscribe to our YouTube Channel here



plus2net.com







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