简体   繁体   English

在python中代替“…”或“…”的“”“…”“”的用法是什么,尤其是在MySQLdb cursor.execute中

[英]What is the use of “”“…”“” in python instead of “…” or '…', especially in MySQLdb cursor.execute

is there a difference if i use """..""" in the sql of cusror.execute. 如果我在cusror.execute的sql中使用““ ..”“”,会有区别吗? Even if there is any slight difference please tell 即使有细微的差别也请告诉

It's used to split the query over many lines to format it nicely: 它用于将查询分成多行以很好地格式化:

db.query("""
    SELECT *
    FROM employee, department 
    WHERE employee.DepartmentID = department.DepartmentID;
""")

Also using """...""" around a string allows you to not escape " and ' inside that string. 还可以在字符串周围使用"""...""" ,以免在字符串内转义"'

不可以,除了字符串可以包含换行符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM