[Tutor] print string using triple quote
Alan Gauld
alan.gauld at btinternet.com
Tue Mar 17 10:54:55 CET 2015
On 17/03/15 04:13, Nick Nguyen wrote:
>
> Hi,
> I use python 3.4.3.
> I'm using print function with triple quote,
> as I understand all the character will be printed
> as exactly within the triple quote, even with
> the backslash character.
You understand wrongly.
Triple quotes are no different to any other kind
of quote except that they can span lines. If you want
to print all the characters (with any kind of quote)
you must precede the quotes with r, for raw.
>>> print ("""A string with \t in it""")
A string with in it
>>> print (r"""A string with \t in it""")
A string with \t in it
>>>
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list