<small id='mGSPI'></small><noframes id='mGSPI'>

        <legend id='mGSPI'><style id='mGSPI'><dir id='mGSPI'><q id='mGSPI'></q></dir></style></legend>
      1. <tfoot id='mGSPI'></tfoot>
        • <bdo id='mGSPI'></bdo><ul id='mGSPI'></ul>
        <i id='mGSPI'><tr id='mGSPI'><dt id='mGSPI'><q id='mGSPI'><span id='mGSPI'><b id='mGSPI'><form id='mGSPI'><ins id='mGSPI'></ins><ul id='mGSPI'></ul><sub id='mGSPI'></sub></form><legend id='mGSPI'></legend><bdo id='mGSPI'><pre id='mGSPI'><center id='mGSPI'></center></pre></bdo></b><th id='mGSPI'></th></span></q></dt></tr></i><div id='mGSPI'><tfoot id='mGSPI'></tfoot><dl id='mGSPI'><fieldset id='mGSPI'></fieldset></dl></div>

        显示带前导零的数字

        时间:2023-09-11

                <legend id='AZcPp'><style id='AZcPp'><dir id='AZcPp'><q id='AZcPp'></q></dir></style></legend>
                <tfoot id='AZcPp'></tfoot>
                <i id='AZcPp'><tr id='AZcPp'><dt id='AZcPp'><q id='AZcPp'><span id='AZcPp'><b id='AZcPp'><form id='AZcPp'><ins id='AZcPp'></ins><ul id='AZcPp'></ul><sub id='AZcPp'></sub></form><legend id='AZcPp'></legend><bdo id='AZcPp'><pre id='AZcPp'><center id='AZcPp'></center></pre></bdo></b><th id='AZcPp'></th></span></q></dt></tr></i><div id='AZcPp'><tfoot id='AZcPp'></tfoot><dl id='AZcPp'><fieldset id='AZcPp'></fieldset></dl></div>

                <small id='AZcPp'></small><noframes id='AZcPp'>

                • <bdo id='AZcPp'></bdo><ul id='AZcPp'></ul>
                    <tbody id='AZcPp'></tbody>
                  本文介绍了显示带前导零的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  给定:

                  a = 1
                  b = 10
                  c = 100
                  

                  如何为所有少于两位数的数字显示前导零?

                  How do I display a leading zero for all numbers with less than two digits?

                  这是我期待的输出:

                  01
                  10
                  100
                  

                  推荐答案

                  在 Python 2(和 Python 3)中你可以这样做:

                  In Python 2 (and Python 3) you can do:

                  number = 1
                  print("%02d" % (number,))
                  

                  基本上 % 类似于 printfsprintf(参见 docs).

                  Basically % is like printf or sprintf (see docs).

                  对于 Python 3.+,同样的行为也可以通过 格式:

                  For Python 3.+, the same behavior can also be achieved with format:

                  number = 1
                  print("{:02d}".format(number))
                  


                  对于 Python 3.6+,使用 f- 可以实现相同的行为字符串:

                  number = 1
                  print(f"{number:02d}")
                  

                  这篇关于显示带前导零的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在不使用 try/except 的情况下检查字符串是否 下一篇:有没有办法将数字单词转换为整数?

                  相关文章

                  最新文章

                  1. <tfoot id='fhwae'></tfoot>

                        <bdo id='fhwae'></bdo><ul id='fhwae'></ul>
                    1. <legend id='fhwae'><style id='fhwae'><dir id='fhwae'><q id='fhwae'></q></dir></style></legend>

                      <i id='fhwae'><tr id='fhwae'><dt id='fhwae'><q id='fhwae'><span id='fhwae'><b id='fhwae'><form id='fhwae'><ins id='fhwae'></ins><ul id='fhwae'></ul><sub id='fhwae'></sub></form><legend id='fhwae'></legend><bdo id='fhwae'><pre id='fhwae'><center id='fhwae'></center></pre></bdo></b><th id='fhwae'></th></span></q></dt></tr></i><div id='fhwae'><tfoot id='fhwae'></tfoot><dl id='fhwae'><fieldset id='fhwae'></fieldset></dl></div>

                      <small id='fhwae'></small><noframes id='fhwae'>