If a string contains a lot of characters need to be escaped, escape will be very troublesome for each character will be.
To avoid this, we can add a prefix before the string r , it indicates that this is a raw string, which do not need to escape the character. E.g:
r'\(~_~)/ \(~_~)/'
But r '...' notation can not represent multi-line string can not contain express 'and' string (Why?)
If you want to represent multi-line string may be '' '...' '' represents:
'''Line 1
Line 2
Line 3'''
Are exactly the same representation of the string above and below are:
'Line 1\nLine 2\nLine 3'
R may also be added in front of the multi-line character string, this string has become a multi-line raw string:
r'''Python is created by "Guido".
It is free and easy to learn.
Let's start learn Python in imooc!'''
task:
Please following string r '' '...' '' rewritable form, and printed out by print:
'\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.'
From writing code:
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''