Python String partition() Method Last Updated : 02 Jan, 2025 Comments Improve Suggest changes Like Article Like Report In Python, the String partition() method splits the string into three parts at the first occurrence of the separator and returns a tuple containing the part before the separator, the separator itself, and the part after the separator. Let's understand with the help of an example: Python s = "Geeks geeks" res = s.partition("for") print(res) Output('Geeks geeks', '', '') Explanation:The string is split into three parts:Part before the separator: 'I love Geeks'The separator: 'for'Part after the separator: ' Geeks'If the separator is found, the method returns a tuple containing these three components.Table of ContentSyntax of partition() methodUsing partition() with a valid separatorSyntax of partition() methodstring.partition(separator)Parameters: separator(required): a substring that separates the stringReturn Type:Returns a tuple of three strings: (before_separator, separator, after_separator).If the separator is not found, the tuple returned is (string, '', '').Using partition() with a valid separatorThis example demonstrates the behavior when the separator exists in the string: Python s = "Python is fun" res = s.partition("is") print(res) Output('Python ', 'is', ' fun') Explanation:The string is split at the first occurrence of the separator "is".The method returns a tuple containing the three parts of the string.When the separator is not foundIf the separator is absent, the partition() method returns a specific result. Python s = "Python is fun" res = s.partition("Java") print(res) Output('Python is fun', '', '') Explanation:Since the separator "Java" is not present in the string, the entire string is returned as the first element of the tuple.The second and third elements are empty strings.Working with multiple occurrences of the separatorpartition() method only considers the first occurrence of the separator: Python s = "Learn Python with GeeksforGeeks" res = s.partition("Python") print(res) Output('Learn ', 'Python', ' with GeeksforGeeks') Explanation:The string is split at the first occurrence of "Python".Subsequent occurrences of the separator are ignored by the partition() method.Using special characters as the separator partition() method works seamlessly with special characters: Python s = "key:value" res = s.partition(":") print(res) Output('key', ':', 'value') Explanation:The string is split into three parts at the occurrence of ":".This method is particularly useful when parsing key-value pairs in a structured format. Comment More infoAdvertise with us Next Article Python String partition() Method pawan_asipu Follow Improve Article Tags : Misc Python python-string Practice Tags : Miscpython Similar Reads Python String isalpha() Method The isalpha() method checks if all characters in a given string are alphabetic. It returns True if every character in the string is a letter and False if the string contains any numbers, spaces, or special characters.Letâs start with a simple example of using isalpha()Pythons1 = "HelloWorld" res1 = 2 min read Python string isdecimal() Method In Python, the isdecimal() method is a quick and easy way to check if a string contains only decimal digits. It works by returning True when the string consists of digits from 0 to 9 and False otherwise. This method is especially useful when we want to ensure that user inputs or string data are stri 3 min read Python String isdigit() Method The isdigit() method is a built-in Python function that checks if all characters in a string are digits. This method returns True if each character in the string is a numeric digit (0-9) and False otherwise. Example:Pythona = "12345" print(a.isdigit()) b = "1234a5" print(b.isdigit())OutputTrue False 3 min read Python String isidentifier() Method The isidentifier() method in Python is used to check whether a given string qualifies as a valid identifier according to the Python language rules. Identifiers are names used to identify variables, functions, classes, and other objects. A valid identifier must begin with a letter (A-Z or a-z) or an 3 min read Python String islower() Method The islower() method in Python checks if all characters in a string are lowercase. It returns True if all alphabetic characters are lowercase, otherwise, it returns False, if there is at least one uppercase letter.Let's look at a quick example of using the islower() method.Pythons = "hello" res = s. 2 min read Python String isnumeric() Method The isnumeric() method is a built-in method in Python that belongs to the string class. It is used to determine whether the string consists of numeric characters or not. It returns a Boolean value. If all characters in the string are numeric and it is not empty, it returns âTrueâ If all characters i 3 min read Python String isprintable() Method Python String isprintable() is a built-in method used for string handling. The isprintable() method returns "True" if all characters in the string are printable or the string is empty, Otherwise, It returns "False". This function is used to check if the argument contains any printable characters suc 3 min read Python String isspace() Method isspace() method in Python is used to check if all characters in a string are whitespace characters. This includes spaces (' '), tabs (\t), newlines (\n), and other Unicode-defined whitespace characters. This method is particularly helpful when validating input or processing text to ensure that it c 2 min read Python String istitle() Method The istitle() method in Python is used to check whether a string follows the title case formatting. In a title-cased string, the first letter of each word is capitalized, and all other letters in the word are in lowercase. This method is especially useful when working with formatted text such as tit 3 min read Python String isupper() method isupper() method in Python checks if all the alphabetic characters in a string are uppercase. If the string contains at least one alphabetic character and all of them are uppercase, the method returns True. Otherwise, it returns False. Let's understand this with the help of an example:Pythons = "GEE 3 min read Like