What does """ means in python?

Walter Hurry walterhurry at gmail.com
Sat Feb 8 14:55:19 EST 2014


Roy Smith wrote:
> In article <72a7dd52-7619-4520-991e-20db7ce55ba3 at googlegroups.com>,
> Sam <lightaiyee at gmail.com> wrote:
>>> For string, one uses "" to represent string. Below is a code fragment that 
>> uses """ instead.
>>>> cursor.execute("""SELECT name, phone_number 
>> FROM coworkers 
>> WHERE name=%s 
>> AND clue > %s 
>> LIMIT 5""",
>> (name, clue_threshold))
>>>> What does """ means in python?
>> This is what's known as a "triple quoted string" It's just like a 
> regular string, except that it run across newlines. Very handy for 
> things like embedding SQL code in a Python program!
>> It works with single quotes too (i.e. '''this is
> a very long string
> spread out over several lines'''

PMFJI.
When I asked (here) about this a while ago, some kind soul suggested textwrap.dedent.
Any advice as to the pros and cons of the respective approaches (esp. for SQL)?


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /