TypeError: not enough arguments for format string(format函数问题)

例如:

a = "156464654654"
b = "652683126541"
c = "{'username':'%s','password':'%s','Submit': '%sjdf'}"%(a,b)
print(c)

  运行这个函数会报错:TypeError: not enough arguments for format string,原因是'Submit': '%sjdf'里面的%在后面的括号中没有定义,所以就会报错not enough argument(没有足够的参数),所以在遇到这种字符串中携带%的情况下,应该在%前面再加一个%号,这样的话Python解释器就会知道这里的情况,例如

a = "156464654654"
b = "652683126541"
c = "{'username':'%s','password':'%s','Submit': '%%sjdf'}"%(a,b)
print(c)

  

原文地址:https://www.cnblogs.com/qiaoer1993/p/10842800.html