Why do we need to use 3 quotes while executing a SQL query from a python cursor?

I came across some Python programs that connect to a MySQL database. In the code, I saw that the request in the function is execute()enclosed in 3 quotes ( """). I would like to know the reason for this. I also noticed that 3 quotes are used only when creating, inserting and updating a table, and not when selecting a row.

cursor.execute("""create table student(id char(10),name char(10))""")
cursor.execute("select * from student")

Why?

+4
source share
1 answer

No need - the encoder who did this decided to use it for some reason (perhaps to add emphasis to this part).

- : . , . :

  • . \n , .
  • . SQL.

, :

>>> type("""a""")
<type 'str'>
>>> type("a")
<type 'str'>
>>>

.

+11

All Articles