PyDocs

Nav

Python Runtime Services

str.partition

builtins

method of str
  • str.partition(sep, /)
Partition the string into three parts using the given separator.

This will search for the separator in the string.  If the separator
is found, returns a 3-tuple containing the part before the
separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing
the original string and two empty strings.
1 Example
>>> 'Monty Python'.partition(' ')
('Monty', ' ', 'Python')
>>> "Monty Python's Flying Circus".partition(' ')
('Monty', ' ', "Python's Flying Circus")
>>> 'Monty Python'.partition('-')
('Monty Python', '', '')
from the Python docs
See Also
No see-alsos for builtins/str.partition
0 Notes
No notes for str.partition