Variables.
Terry Hancock
hancock at anansispaceworks.com
Sat Feb 19 00:57:52 EST 2005
On Wednesday 16 February 2005 03:34 am, administrata wrote:
> sry, I mean the problem is... about lining
>
> it doesn't look like this...
>
> Allen woke up early in the morning. But, it was unusal by Allen.
> Allen's pillow was with Allen. Allen didn't want to wake up But, Allen
> tried my best and woke up. it was so amazing
> --
> http://mail.python.org/mailman/listinfo/python-list
In a triple-quoted string, newlines are significant.
Compare:
>>>
>>> my_text1 = """
... first line of text
... second line of text
... third line of text
... """
>>>
>>> my_text2 = ("first line of text "
... "second line of text "
... "third line of text")
>>>
>>> print my_text1
first line of text
second line of text
third line of text
>>> print my_text2
first line of text second line of text third line of text
>>>
Note that strings that appear together without punctuation are concatenated
*before* byte-compiling, whereas using "+" creates code to concatenated the
strings. This will rarely matter, but it means that the idiom above is completely
equivalent to a long string on a single line, which is probably what you wanted.
You need the parentheses to tell Python that the expression is not complete,
so it won't throw a syntax error when you go to the next line.
There are also more sophisticated ways of processing text, of course -- study the
"textwrap" module, for example.
Cheers,
Terry
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
More information about the Python-list
mailing list