String problem

Chris Liechti cliechti at gmx.net
Sat May 25 17:22:47 EDT 2002


"Occean" <tritran2001 at iprimus.com.au> wrote in
news:20020526.064829.1504569917.16939 at iprimus.com.au: 

> Assume that you have an text article. 
> "Paint my love, you should paint my love
>   It's a picture of thousand sunset 
>   
>   It's a freedom of , a thousand doves
>   ......"
> 
> you have to read the article into a
> string called str and use that string to pass into the function called
> display(str). This function will display the exact content of the
> article back into the screen. The problem is when you read the article
> in the string you have to put "\n\" at the end of each line in order
> to let the system know the new line. For example:
> str = ' Paint my love, you should paint my love\n\

"str" is a builtin function, i would choose an other name for the variable 
:-)

>          It's a picture of thousand sunset \n\
>          \n\
>           It's a freedom of , a thousand doves\n\'
> 
> I Just wondering are there another to do that without insert  "\n\"
> into the end of each line.

use triple quotes an the newlines in the string stay in:

s = """this is
a long
string"""

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list