Python String partition() Method
Python partition() method splits the string from the string specified in parameter. It splits the string from at the first occurrence of parameter and returns a tuple. The tuple contains the three parts before the separator, the separator itself, and the part after the separator.
It returns an empty tuple having seperator only, if the seperator not found.
The method signature is given below.
sep: A string parameter which separates the string.
It returns a tuple, A 3-Tuple.
Let's see some examples of partition(sep) method to understand it's functionality.
Python String partition() Method Example 1
First, let's see simple use of partition method.
Python String partition() Method Example 2
if the separator is not found, It returns a tuple containing string itself and two empty strings. See the example below.
('Java is a programming language', '', '')
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week