【发布时间】:2020-02-21 03:52:34
【问题描述】:
我需要根据两个字符串参数创建一个动态查询:
description = "This is the description"
comment = "This is the comment"
query = "insert into case(desc, comm) value(description, comment)"
注意: 描述和评论中可能有单引号和双引号。
如何使用格式化的 %s 生成查询字符串?
非常感谢。
更新:
感谢 Green Cloak Guy(他/她的回答有未成年人需要纠正),正确的查询是:
query = f"插入 case(description,comment) value(\'{description}\', \'{comment}\')"
【问题讨论】:
标签: python-3.x string-concatenation