gpt4 book ai didi

python - Python 中的字符串格式化 %i

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

我必须将代码从 Python2.x 转换为 Python3(主要是字符串格式)我遇到过这样的事情:

Logger.info("random String %d and %i".format(value1, value2))

现在,我知道 %d 可以替换为 {:d} 但找不到 %i 的等效项(已签名)使用 {:i} 会出现以下错误:

ValueError:“int”类型对象的未知格式代码“i”

最佳答案

在 Python 中,%d%i 没有区别,所以你可以用同样的方式翻译它们。 %i 的存在只是为了与其他语言的 printf 函数兼容。

关于python - Python 中的字符串格式化 %i,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53813164/

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