16

I have a string

a=">NKMFFALGLLGDGVIGALDTVVSSMGAVGASGLS"

I want print a as

">
NKMFFALGLLGDGVIGALDTVVSSMGAVGASGLS"

I did a=a.replace(">","> \n") but it doesn't work. Where am I going wrong?

4
  • What do you mean by "doesn't work"? Commented Jul 5, 2011 at 7:20
  • I get the output as '> \n NKMFFALGLLGDGVIGALDTVVSSMGAVGASGLS' Commented Jul 5, 2011 at 7:20
  • 1
    It works for me. Try using print. Commented Jul 5, 2011 at 7:21
  • repr() escapes the backslashes, there is no problem here. Commented Jul 5, 2011 at 7:22

1 Answer 1

24

One thing is the internal representation of the string:

>>> a=">NKMFFALGLLGDGVIGALDTVVSSMGAVGASGLS"
>>> a.replace(">","> \n")
'> \nNKMFFALGLLGDGVIGALDTVVSSMGAVGASGLS'

another one is how it will be shown on screen:

>>> print(a.replace(">","> \n"))
> 
NKMFFALGLLGDGVIGALDTVVSSMGAVGASGLS
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.