Other methods are discussed in this article
1. strip () : — This method is used to remove all leading and trailing characters mentioned in its argument.
2. lstrip () : — This method is used to remove all leading characters mentioned in its argument.
3. rstrip () : — This method is used to remove all trailing characters mentioned in its argument.
String after stripping all ’-’ is: pythonengineering String after stripping all leading ’-’ is: pythonengineering --- String after stripping all trailing’ -’ is: --- pythonengineering
4. min ("string") : — This function returns the alphabet of minimum value from a string.
5. max ("string") : — This function returns the alphabet of maximum value from a string.
The minimum value character is: e The maximum value character is: s
6. maketrans () : — It is used to match the contents of line 1 to line 2 with the appropriate indices for subsequent translation using translate ().
7. translate () : — Used to swap inline elements matched with maketrans ().
The string after translation using mapped elements is: aeeksbcraeeks
In the above code, "g" is replaced with "a", "f" is replaced with "b" and "o" is replaced with "c" in the string using the translation function.
8.replace () : — This function is used to replace a substring with a new substring in a string. This function has 3 arguments. The string to replace, the newline to replace, and the maximum value indicating the limit for overwriting the action (default is unlimited).
The string after replacing strings is: pythonengineering is for nerds
This method is provided by Chinmoy Lenka
9. expandtabs () : — It is used to replace all tabs ("/ t") with spaces or just spaces, using a specified tab size, which is optional.
Syntax: string.tabsize (tabsize)
Parameters: specifies the number of characters to replace for one tab character. By default, the function accepts the tab size as 8.
Returned value: a string in which all tabs are replaced by spaces.
GEEKS FOR GEEKS GEEKS FOR GEEKS GEEKS FOR GEEKS
This article is updated Manjeet Singh If you love Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by mailing the article [email protected] See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.