Practical Application

 Given a string remove the occurrence of the word “the” from the beginning and the end. we will Python String Trim.

Python




# Python3 program to demonstrate the practical application
# strip() 
  
string = " the King has the largest army in the entire world the" 
  
# strip function works on characters and removes characters till it sees, 
# the last or beginning characters mentioned in the function has been removed
print(string.strip(" eht"))


Input

the King has the largest army in the entire world the

Output

King has the largest army in the entire world


Python string | strip()

Python String strip() is an inbuilt function in the Python programming language that returns a copy of the string with both leading and trailing characters removed (based on the string argument passed). This article will examine the many features and use cases of the strip() method to give you a thorough grasp of how to use it successfully in your Python programs.

Similar Reads

Python strip() Method Syntax

Syntax: string.strip([chars]) Parameter: There is only one optional parameter in it. chars – a string specifying the set of characters to be removed. If the optional chars parameter is not given, all leading and trailing whitespaces are removed from the string. Return Value: Returns a copy of the string with both leading and trailing characters removed....

Purpose of the Python Strip() Function

When a developer wishes to remove characters or whitespaces from the beginning or end of a string, the Strip() function in Python comes in handy. Let’s take a closer look at it:...

String strip() in Python Example

In Python, the strip() method is used to remove leading and trailing whitespace characters (spaces, tabs, and newlines) from a string. It returns a new string with the whitespace characters removed. The original string remains unchanged....

Practical Application

...