Some of the string methods are covered in below sets.
More methods are discussed in this article
1. strip() :- This method is used to delete all the leading and trailing characters mentioned in its argument.
2. lstrip() :- This method is used to delete all the leading characters mentioned in its argument.
3. rstrip() :- This method is used to delete all the trailing characters mentioned in its argument.
String after stripping all '-' is : geeksforgeeks String after stripping all leading '-' is : geeksforgeeks--- String after stripping all trailing '-' is : ---geeksforgeeks
4. min(“string”) :- This function returns the minimum value alphabet from string.
5. max(“string”) :- This function returns the maximum value alphabet from string.
The minimum value character is : e The maximum value character is : s
6. maketrans() :- It is used to map the contents of string 1 with string 2 with respective indices to be translated later using translate().
7. translate() :- This is used to swap the string elements mapped with the help of maketrans().
The string after translation using mapped elements is : aeeksbcraeeks
In the above code, ‘g’ is replaced by a, ‘f’ is replaced by b and ‘o’ is replaced by ‘c’ in the string using translate function.
8.replace() :- This function is used to replace the substring with a new substring in the string. This function has 3 arguments. The string to replace, new string which would replace and max value denoting the limit to replace action ( by default unlimited ).
The string after replacing strings is : geeksforgeeks is for nerds
This method is contributed by Chinmoy Lenka
9. expandtabs() :- It is used to replace all tab characters(“\t”) with whitespace or simply spaces using the given tab size, which is optional to supply.
Parameters: Specifying the number of characters to be replaced for one tab character. By default, the function takes tab size as 8.
Return Value: A string in which all the tab characters are replaced with spaces.
GEEKS FOR GEEKS GEEKS FOR GEEKS GEEKS FOR GEEKS
This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Python | Pandas Series.str.strip(), lstrip() and rstrip()
- Python | maketrans() and translate() functions
- Python | String rstrip()
- Python String | lstrip() method
- Python String | strip()
- Python string | strip()
- Python | String translate()
- numpy string operations | rstrip() function
- numpy string operations | lstrip() function
- Python | Numpy expandtabs() method
- Python 3 Strings | expandtabs() method
- numpy string operations | strip() function
- Python String | replace()
- Python - Kth word replace in String
- Python - Replace duplicate Occurrence in String
- Python - Replace Substrings from String List
- Python - Replace all occurrences of a substring in a string
- Python | Replace rear word in String
- Python | Multiple indices Replace in String
- numpy string operations | translate() function
Improved By : NelsonSelvam