why the output is different when i am implementig multiline string

Dave Angel d at davea.name
Wed Jan 2 15:22:16 CET 2013


On 01/02/2013 09:00 AM, stringsatif1 at gmail.com wrote:
>>>> '''hello
> world'''
> 'hello\nworld'
>>>> fred=''' hello
> world'''
>>>> print(fred)
>  hello
> world

What you're seeing has nothing to do with the triple quotes, and
everything to do with how you're using the debugger.  In one case, you
just mention a value, and the debugger magically calls repr() on the
expression.  So it adds quotes around it, and turns embedded funny stuff
into escape sequences, because that's what repr() does on a string.

In the second case, you call Python's print function (assuming python 3,
which you didn't specify).  it does not call repr(), but just sends the
characters direct to the console.

if you want to see the escape characters in the second case, you should
have either said:

>>>fred

or

>>>print(repr(fred))



-- 

DaveA




More information about the Python-list mailing list