How to trim a string in python?
We have three functions to trim a string in python.
- strip()- This function trims the string by removing all whitespaces from right and left of the string.
e.g.,
s=" pythonpoint " print(s.strip())
- lstrip()- This function removes the whitespaces from the left of the string.
e.g.,
s=" pythonpoint" print(s.lstrip())
- rstrip()- This function removes the whitespaces from the right of the string.
e.g.,
s="pythonpoint " print(s.rstrip())
This is how we can trim string in python.
Subscribe
Login
Please login to comment
0 Discussion