FAQ: String Methods - .strip()


This community-built FAQ covers the “.strip()” exercise from the lesson “String Methods”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science

FAQs on the exercise .strip()

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


Im starting to get frustrated over the way that you learn from codecademy. For example in this excercise it didn´t say in the instructions that you think about iterating/forloop (or whats it called) to be able to strip the list. The example was not even close to prepare you for that.


As said by jansson173, i didn’t expect the answer to be in for loop for the first part.
I wrote my code simply like this:

love_maybe_lines_stripped = love_maybe_lines.strip()

How is that this code above is wrong? How is that using a for loop in this exercise suits well?

>>> love_maybe_lines.strip()
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
AttributeError: 'list' object has no attribute 'strip'

We need to parse out the individual lines which as strings DO have a strip() method.


Can somebody explain why the code below prints out " to conquer me home. " instead of every line?

for line in love_maybe_lines:

Yet, when the code below adds every line to the empty list.

love_maybe_lines_stripped =
for line in love_maybe_lines:


Your first example does not append anything to a list, just prints the unchanged line. strip() is not an insitu operation but one that needs to be redirected to a variable or a print statement.

for line in love_maybe_lines:
    print (line.strip())

line, itself is not modified. Only the printed value is stripped.

We’re not instructed to modify the original list, only to create a spinoff list of modified strings.

for line in love_maybe_lines:

as the solution has shown. In either event, we had to redirect (assign) the outcome to some other object or process. APPEND assigns it to a list; PRINT passes it as an argument to a process (in Python 3 it is a function). The act of stripping has no effect upon the object being stripped.