Python String strip() Method Last Updated : 01 May, 2025 Comments Improve Suggest changes Like Article Like Report strip() method in Python removes all leading and trailing whitespace by default. You can also specify a set of characters to remove from both ends. It returns a new string and does not modify the original.Let's take an example to remove whitespace from both ends of a string. Python s = " GeeksforGeeks " res = s.strip() print(res) OutputGeeksforGeeks Explanation: s.strip() removes spaces at the start and end of the string.Syntaxs.strip(chars)Parameters:chars(optional): A string specifying the set of characters to remove from the beginning and end of the string.Return Type: A new string with specified characters removed from both ends.Examples of strip() MethodRemoving Custom CharactersWe can also use custom characters from the beginning and end of a string. This is useful when we want to clean up specific unwanted characters such as symbols, punctuation, or any other characters that are not part of the core string content Python s = ' ##*#GeeksforGeeks#**## ' res = s.strip('#* ') print(res) OutputGeeksforGeeks Explanation:strip('#* ') removes any #, *, and spaces from both beginning and end of the string.It stops stripping characters from both end once it encounters a character that are not in the specified set of characters.Removing Newline CharactersWe can also remove the leading and trailing newline characters (\n) from a string. Python s = '\nGeeks for Geeks\n' res = s.strip() print(res) OutputGeeks for Geeks Explanation: Removes newline characters \n from both ends of the string.Strip Tabs and Spaces Python s = '\t Hello World \t' res = s.strip() print(res) OutputHello World Explanation: Removes both tabs (\t) and spaces from the start and end of the string.Related articles: newline characters (\n) Comment More infoAdvertise with us Next Article Python String strip() Method S Striver Follow Improve Article Tags : Misc Python python-string Practice Tags : Miscpython Similar Reads 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 Python String join() Method The join() method in Python is used to concatenate the elements of an iterable (such as a list, tuple, or set) into a single string with a specified delimiter placed between each element.Lets take a simple example to join list of string using join() method.Joining a List of StringsIn below example, 3 min read String lower() Method in Python lower() method in Python converts all uppercase letters in a string to their lowercase. This method does not alter non-letter characters (e.g., numbers, punctuation). Let's look at an example of lower() method:Pythons = "HELLO, WORLD!" # Change all uppercase letters to lowercase res = s.lower() prin 3 min read Python String lstrip() Method The lstrip() method removes leading whitespace characters from a string. We can also specify custom characters to remove from the beginning/starting of the string.Let's take an example to remove whitespace from the starting of a string.Pythons = " Hello Python!" res = s.lstrip() print(res)OutputHell 2 min read Python String partition() Method 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:Pythons = "Geeks gee 3 min read Python String replace() Method The replace() method replaces all occurrences of a specified substring in a string and returns a new string without modifying the original string.Letâs look at a simple example of replace() method.Pythons = "Hello World! Hello Python!" # Replace "Hello" with "Hi" s1 = s.replace("Hello", "Hi") print( 2 min read Python String rfind() Method Python String rfind() method returns the rightmost index of the substring if found in the given string. If not found then it returns -1.ExamplePythons = "GeeksForGeeks" print(s.rfind("Geeks"))Output8 Explanationstring "GeeksForGeeks" contains the substring "Geeks" twice.rfind() method starts the sea 4 min read Python String rindex() Method Python String rindex() method returns the highest index of the substring inside the string if the substring is found. Otherwise, it raises ValueError.Let's understand with the help of an example:Pythons = 'geeks for geeks' res= s.rindex('geeks') print(res)Output10 Note: If start and end indexes are 2 min read Python String rpartition() Method String rpartition() method in Python is a powerful tool for splitting a string into three parts, based on the last occurrence of a specified separator. It provides an efficient way to handle text parsing when we want to divide strings from the rightmost delimiter. Let us start with a simple example: 4 min read Python String rsplit() Method Python String rsplit() method returns a list of strings after breaking the given string from the right side by the specified separator. It's similar to the split() method in Python, but the difference is that rsplit() starts splitting from the end of the string rather than from the beginning. Exampl 3 min read Like