.strip() in the Audre Lorde poem, Love, Maybe

Hi there,

On this exercise, I am little confused as to what is happening, in specific to the ‘\n’ on the first part.

For example, on the first part they ask to get rid of all the white space which worked:

love_maybe_lines = ['Always    ', '     in the middle of our bloodiest battles  ', 'you lay down your arms', '           like flowering mines    ','\n' ,'   to conquer me home.    ']

#print(love_maybe_lines)

love_maybe_lines_stripped = []
for line in love_maybe_lines:
  love_maybe_lines_stripped.append(line.strip())
print(love_maybe_lines_stripped)

The above has not only removed the empty spaces but also the : ‘\n’.

My question about the above is, wouldn’t the “.strip()” method without any parameters passed to it, remove only white spaces? Which it also did, but along with the white spaces it also stripped the ‘\n’ string. Why?

The second part of the exercise it’s about joining the lines into a multi line string, and each line of the poem must show on its own line. So, the original list after being processed by the first loop is:

Then writing this:

love_maybe_full = '\n'.join(love_maybe_lines_stripped)

print(love_maybe_full)

It becomes this:

Always
in the middle of our bloodiest battles
you lay down your arms
like flowering mines

to conquer me home.

So, my question is, is there an implicit ‘\n’(new line) character between the strings in the list above so that the join() function reads and so the Python interpreter knows where to start and end each line?

‘\n’ is a whitespace character, the space' ' and tab'\t' are other whitespace characters.

love_maybe_full = '\n'.join(love_maybe_lines_stripped)
puts a ‘\n’ between each string of the love_maybe_lines_stripped list to make a new string. (That’s what .join does.)

2 Likes