如何在 python 中使用 zfill 作为递增计数器?

How to use zfill as increment counter in python?

我想开始计数 00000_keypoints, 00001_keypoints.....

c = 0
{my code}
c += 1

我如何使用 zfill?由于 zfill 仅适用于字符串。

您不需要 zfill:

s = f"{c:05d}_keypoints"

您可以使用 f-string(我推荐)或 zfill

for i in range(n):
    name1 = f"{i:05d}_keypoints"
    name2 = "{}_keypoints".format(str(i).zfill(5))
    print(name1, name2)
    # your code here

我找到了一种使用 zfill 解决问题的方法。谢谢

f"{str(c).zfill(5)}_keypoints"