gpt4 book ai didi

python格式字符串TypeError : not all arguments converted during string formatting

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:27 25 4
gpt4 key购买 nike

有很多条目,根据:"TypeError: not all arguments converted during string formatting"但我没有找到原因,为什么会这样:

print("File: %30s "%("name"))

正在工作,但不是这个:

leng=30
print("File: %"+ str(leng) +"s "%("name"))

最佳答案

由于操作顺序,您的代码评估为:

"File: %" + str(leng) + ("s "%("name"))

要解决此问题,只需将字符串括起来,如:

("File" + ...)%("name")

关于python格式字符串TypeError : not all arguments converted during string formatting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47594101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com