.partition()
design246136080119 total contributions
Published Jun 9, 2021Updated Oct 13, 2023
Contribute to Docs
Searches a string for a given keyword and splits that string into a three part tuple.
Syntax
string.partition("keyword")
Example
The .partition()
method searches for an exact match of the given keyword:
my_string = "Do not go gentle into that good night"my_tuple = my_string.partition("gentle")print(my_tuple)# Output: ('Do not go ', 'gentle', ' into that good night')
No Match Found
If no match is found, .partition()
will return a tuple with the full string, followed by two empty strings
Multiple Matches
If there are multiple matches, the first one will be used:
All contributors
- design246136080119 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- CyberRedPanda27 total contributions
- design2461360801
- christian.dinh
- Anonymous contributor
- CyberRedPanda
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.