- In python, we have different functions which remove the spaces between the strings.
- There are three functions that remove the whitespace between the strings, they are:
- strip(), rstrip(), lstrip() are the three functions having the same meaning but some differences.
syntax: str.strip()
lstrip(): It removes the whitespace at beginning of the string.
syntax: str.rstrip()
rstrip(): It removes the whitespace at end of the string.
syntax: str.rstrip()
Example: write a python to demonstrate the remove space function.
- txt=" hello"
- print(txt)
- print(txt.strip())
- print(txt.rstrip())
- print(txt.lstrip())
Output: hello //this is the original output
hello //after removing both side space
hello //no space at end returns same
hello //remove space at the beginning.
No comments