“%s” % format vs “{0}”.format() vs “?” format

后端 未结 3 695
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 16:42

In this post about SQLite, aaronasterling told me that

  • cmd = \"attach \\\"%s\\\" as toMerge\" % \"b.db\" : is wrong
  • cmd = \'attach
3条回答
  •  时光取名叫无心
    2020-12-08 17:26

    The first and second produce the same result, but the second method is prefered for formatting strings in newer versions of Python.

    However the third is the better approach here because it uses parameters instead of manipulating strings. This is both faster and safer.

提交回复
热议问题