"Adam Bark" <adam.jt...@gmail.com> wrote

>>> test=r"a \n b \n c \n"
>>> test.replace(r"\n","***")
'a *** b *** c ***'

>>> test2="""
... a
... b
... c
... """
>>> test2.replace(r"\n","***")
'\na\nb\nc\n'

In your first example you put the characters into the string test and replaced the characters. The second example you have actual newlines and are searching for the characters "/n" which don't exist in your string.

Just to further emphasise this point try printing your strings (using print())
and you will see the difference:

test = r"a \n b \n c \n"  # using raw 'r'
test2 = """
... a
... b
... c
... """
test3 = "a \n b \n c \n"  # no raw 'r'
print(test)
a \n b \n c \n
print( test2)

a
b
c

print(test3)
a
b
c



HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to