[Tutor] print string using triple quote
Dave Angel
davea at davea.name
Tue Mar 17 11:40:34 CET 2015
On 03/17/2015 05:54 AM, Alan Gauld wrote:
> 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
> >>>
And a raw string literal cannot easily have a backslash as the final
character. Sometimes it's good enough to just add a space at the end of
a raw string.
--
DaveA
More information about the Tutor
mailing list