Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 4 weeks ago

Why does .rstrip() work for list comprehensions but not for for loops?

I know it's a string method, but what's the difference? 

Update:

Why would I have to show code for this question??? Like what?

Update 2:

When did I say "I WISH" it to? I'm asking about the how the language works. 

Update 3:

All of that TV has melted your brain.

Update 4:

I was not talking to husoski Brilliant_movies, the commenter I was replying to was removed because he broke Yahoo's rules and was being a douche.

2 Answers

Relevance
  • 4 weeks ago
    Favorite Answer

    So far, the correct answer seems to be, "Who *said* that .rstrip() doesn't work with for loops?"

    For example:

        for c in 'abc \n'.rstrip():

            print(c)

    So, you seem to be doing something else that doesn't work; and then blaming that on .rstrip().  *That's* why you need to show code...so someone who feels helpful might show you what your misconception is.

  • 4 weeks ago

    You wrote: Why does .rstrip() work for list comprehensions but not for for loops?" Well, it does work for for loops, as @Husoski has kindly showed you, giving an example to back it up. I think he deserves more respect for sharing his wisdom here, for free.

Still have questions? Get your answers by asking now.