Python String rstrip() Method Last Updated : 12 Nov, 2024 Comments Improve Suggest changes Like Article Like Report The rstrip() method removes trailing whitespace characters from a string. We can also specify custom characters to remove from end of string.Let's take an example to remove whitespace from the ends of a string. Python s = "Hello Python! " res = s.rstrip() print(res) OutputHello Python! Syntax of rstrip() Methods.rstrip(chars)s: The input stringchars (optional): A set of characters to remove as trailing charactersTable of ContentSyntax of rstrip() MethodExamples of rstrip() MethodRemove trailing whitespacesRemove Custom CharactersRemove Newline CharactersFrequently Asked Questions (FAQs) on Python rstrip() MethodExamples of rstrip() MethodRemove Trailing Whitespaces Python s = " Hello Python! " res = s.rstrip() print(res) Output Hello Python! Remove Custom CharactersIf we have a string with various characters that we want to remove from end of the string. Python s = ' ##*#Hello Python!#**## ' # removes all occurrences of '#', '*', and ' ' # from the end of string res = s.rstrip('#* ') print(res) Output ##*#Hello Python! Notes:rstrip('#* ') removes any #, *, and spaces from the end of string.It stops stripping characters from the end of string once it encounters a character that are not in the specified set of characters.Remove Newline CharactersWe can also remove the trailing newline characters (\n) from a string. Python s = '\nHello Python!\n' # Removing newline characters # from the end of string res = s.rstrip() print(res) OutputHello Python! Comment More infoAdvertise with us Next Article Python String rstrip() Method A Akanksha_Rai Follow Improve Article Tags : Python Python-string-functions python-string Practice Tags : python Similar Reads 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 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 Like