I came across some Python programs that connect to a MySQL database. In the code, I saw the query in the execute()
function is enclosed withing 3 quotations(
It is not needed--the coder who made that just decided to use it for some reason (probably to add emphasis on that part).
A triple-quoted string is just that: a string. It has the same properties as a regular string object. There are only two differences:
\n
every time you want a newline.In summary though, a triple-quoted string is a string:
>>> type("""a""")
<type 'str'>
>>> type("a")
<type 'str'>
>>>
and it is not needed in that code.