What does """ means in python?

Roy Smith roy at panix.com
Sat Feb 8 15:08:09 CET 2014


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'''



More information about the Python-list mailing list