Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在格式中添加前导零?_Ios_Python 3.x_Format_Leading Zero - Fatal编程技术网

Ios 如何在格式中添加前导零?

Ios 如何在格式中添加前导零?,ios,python-3.x,format,leading-zero,Ios,Python 3.x,Format,Leading Zero,我需要一个打印函数,它可以写入循环I/round,其中I和round两个值必须至少有四位数(12->0012)。它也必须有格式化方法 我找到了粘贴格式和其他添加前导零的方法,但我无法使它们适用于这种情况 它必须是这样的: print('Loop {} / {}'.format('i', 'round')) 但正如我所说,是四位数的 number_str = str(a_number) zero_filled_number = number_str.zfill(4) 号码是12。 零填充的数字

我需要一个打印函数,它可以写入
循环I/round
,其中
I
round
两个值必须至少有四位数
(12->0012)
。它也必须有格式化方法

我找到了粘贴格式和其他添加前导零的方法,但我无法使它们适用于这种情况

它必须是这样的:

print('Loop {} / {}'.format('i', 'round'))
但正如我所说,是四位数的

number_str = str(a_number)
zero_filled_number = number_str.zfill(4)
号码是12。
零填充的数字将为您提供0012

使用
打印(“{:02d}”。格式(1))
,如答案所示。

欢迎使用!你能展示一下到目前为止你做了什么来解决你的问题吗(不是一些含糊的陈述)?您需要学习如何循环,这是一个基本概念。因此,这不是教程的替代品。