If you can comment out code and your program still works, then yes, that code was optional.

.strip() with no arguments (or None as the first argument) removes all whitespace at the start and end, including spaces, tabs, newlines and carriage returns. Leaving it in doesn't do any harm, and allows your program to deal with unexpected extra whitespace inserted into the file.

For example, by using .strip(), the following two lines in a file would lead to the same end result:

 foo\tbar \n
foo\tbar\n

I'd say leave it in.

Answer from Martijn Pieters on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_string_strip.asp
Python String strip() Method
Python Examples Python Compiler ... Study Plan Python Interview Q&A Python Training ... The strip() method removes any leading, and trailing whitespaces....
🌐
Reddit
reddit.com › r/learnpython › how does the strip() method really work?
r/learnpython on Reddit: How does the strip() method really work?
May 3, 2023 -

I want to strip a certain word off of a string. I tried doing this.

string= "Germany Income and Capital Tax Treaty"
string = string.lower().strip('germany')
print(string)

I expected to get:"income and capital tax treaty"

Instead I get"income and capital tax treat"

What is it that I do not understand. Also lstrip and rstrip would not provide a solution as I am writing this in a function where a complete match with the word would need to get stripped off of 'either' end.

Any help?

Discussions

String.strip() in Python - Stack Overflow
While learning about python, I came upon this code, which takes a text file, splits each line into an array, and inserts it into a custom dictionary, where the array[0] is the key and array[1] is the More on stackoverflow.com
🌐 stackoverflow.com
Python strip with \n - Stack Overflow
This is my problem. I'm trying to read a text file and then convert the lines into floats. The text file has \n and \t in it though I don't know how to get rid of it. I tried using line.strip() b... More on stackoverflow.com
🌐 stackoverflow.com
.strip function not working in VS code (python)
I’m trying to get rid of whitespace in my code. Ex: name = name.strip() It initially worked but now it is refusing to work. Is this a path issue? I’m a beginner and I’m lost. More on discuss.python.org
🌐 discuss.python.org
8
0
July 30, 2023
strip() function usage in Python - Stack Overflow
The strip() function removes all leading and trailing characters. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Mimo
mimo.org › glossary › python › string-strip
Python string.strip(): Syntax, Usage, and Examples
The Python string.strip() method cleans unwanted characters from both ends of a string, making your data ready for comparison, storage, or display.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-strip
Python String strip() Method - GeeksforGeeks
July 1, 2026 - DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 1 Jul, 2026 · strip() method removes specified characters from both the beginning and the end of a string.
🌐
Python
docs.python.org › 3.4 › library › stdtypes.html
4. Built-in Types — Python 3.4.10 documentation
>>> ' spacious '.strip() 'spacious' >>> 'www.example.com'.strip('cmowz.') 'example'
Find elsewhere
🌐
Real Python
realpython.com › python-strip
How to Strip Characters From a Python String – Real Python
October 22, 2025 - By default, Python’s .strip() method removes whitespace characters from both ends of a string. To remove different characters, you can pass a string as an argument that specifies a set of characters to remove.
🌐
Codecademy
codecademy.com › docs › python › strings › .strip()
Python | Strings | .strip() | Codecademy
April 23, 2025 - The .strip() method, when used without arguments, removes all these whitespace characters from both ends of a string. Preview: Anonymous contributor 36 total contributions ... Looking for an introduction to the theory behind programming?
🌐
Hyperskill
hyperskill.org › university › python › strip-in-python
Python strip(), lstrip(), rstrip(): Remove Whitespace & Characters
June 5, 2026 - The Python strip() function is a tool that clears out any extra characters at the beginning and end of a string. Its commonly used to get rid of spaces.
🌐
YouTube
youtube.com › watch
Make text processing easier with .strip() - YouTube
This is a preview of the video course, "Strip Characters From a Python String". By default, Python’s .strip() method removes whitespace characters from both ...
Published: September 25, 2025
🌐
Great Learning
mygreatlearning.com › blog › it/software development › strip() function in python with examples
Strip() Function in Python with Examples
November 6, 2023 - By default, the strip() method helps to remove whitespaces from the start and the end of the string. Python's strip() method is a string operation that is used to remove specific characters from both the beginning and the end of a string.
🌐
Real Python
realpython.com › videos › strip-characters-from-string-overview
Strip Characters From a Python String (Overview) (Video) – Real Python
By default, Python’s .strip() method removes whitespace characters from both ends of a string. To remove different characters, you can pass a string as an argument that specifies a set of characters to remove.
Published: September 23, 2025
🌐
Programiz
programiz.com › python-programming › methods › string › strip
Python String strip()
Online Python Online JavaScript ... Rust Online Scala Online Dart Online R Online Ruby ... The strip() method removes any leading (starting) and trailing (ending) whitespaces from a given string....
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › str › strip.html
strip — Python Reference (The Right Way) 0.1 documentation
>>> ' spacious '.strip() 'spacious' >>> "AABAA".strip("A") 'B' >>> "ABBA".strip("AB") '' >>> "ABCABBA".strip("AB") 'C'
🌐
Python
docs.python.org › 3.6 › library › stdtypes.html
4. Built-in Types — Python 3.6.15 documentation
>>> comment_string = '#....... Section 3.2.1 Issue #32 .......' >>> comment_string.strip('.#! ') 'Section 3.2.1 Issue #32'
🌐
Python.org
discuss.python.org › python help
.strip function not working in VS code (python) - Python Help - Discussions on Python.org
July 30, 2023 - I’m trying to get rid of whitespace in my code. Ex: name = name.strip() It initially worked but now it is refusing to work. Is this a path issue? I’m a beginner and I’m lost.
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.7 documentation
The chars argument is not a suffix; rather, all combinations of its values are stripped. For example: >>> ' spacious '.rstrip() ' spacious' >>> 'mississippi'.rstrip('ipz') 'mississ' See removesuffix() for a method that will remove a single suffix string rather than all of a set of characters. For example: >>> 'Monty Python'.rstrip(' Python') 'M' >>> 'Monty Python'.removesuffix(' Python') 'Monty'
🌐
Epic Zoe
yvonnezoe.wordpress.com › 2013 › 05 › 07 › python-strip-method
Python .strip() method | Epic Zoe
May 7, 2013 - The most significant byte is on the right. e.g FF00 – FF is least significant byte and 00 is most significant byte. The data that i would like to display is only the “ss” part. So, to extract “ss” from the readlines reply, the method str.strip(chars) is used.