How to Answer: How to remove the leading and trailing whitespaces in Python?
Advice and answer examples written specifically for a Python Beginner job interview.
3. How to remove the leading and trailing whitespaces in Python?
This question is to test the knowledge about Python methods.
This can be done by using strip(). It is a method that removes any starting and ending whitespace in a given string. The code below shows how to use it.
str= " It is a python interview "
final=str.strip()
If you run the code and print the final, you will see the final="It is a python interview". It has stripped away all whitespace from beginning and end.
Written by Aiad Asaad on April 15th, 2021