22-Mar-2023
.
Admin
Hi Dev,
This tutorial shows you how to remove whitespace from the start and end of the string in python. I’m going to show you about python removes whitespace from the start and end of a string. We will look at an example of python removing space from the start and end of a string. if you want to see an example of python trim whitespace from the beginning and end of a string then you are the right place.
In this example, I will add myString variable with the hello string. Then we will use the strip() function to whitespace from the start and end of the string in python. So, without further ado, let's see simple examples: You can use these examples with the python3 (Python 3) version.
Example
main.py
# Declare String Variable
myString = " Hello, This is nicesnippets.com, This is awesome. "
# Python string remove all spaces
myString = myString.strip()
print(myString)
Output:
Hello, This is nicesnippets.com, This is awesome.
#Python