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

    2. <small id='MpEbH'></small><noframes id='MpEbH'>

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

          <bdo id='MpEbH'></bdo><ul id='MpEbH'></ul>
        <legend id='MpEbH'><style id='MpEbH'><dir id='MpEbH'><q id='MpEbH'></q></dir></style></legend>

      1. 如何从 0000 循环到 9999 并将数字转换为相对字符串?

        how to loop from 0000 to 9999 and convert the number to the relative string?(如何从 0000 循环到 9999 并将数字转换为相对字符串?)
        • <bdo id='9J6zG'></bdo><ul id='9J6zG'></ul>
          <tfoot id='9J6zG'></tfoot>
          <i id='9J6zG'><tr id='9J6zG'><dt id='9J6zG'><q id='9J6zG'><span id='9J6zG'><b id='9J6zG'><form id='9J6zG'><ins id='9J6zG'></ins><ul id='9J6zG'></ul><sub id='9J6zG'></sub></form><legend id='9J6zG'></legend><bdo id='9J6zG'><pre id='9J6zG'><center id='9J6zG'></center></pre></bdo></b><th id='9J6zG'></th></span></q></dt></tr></i><div id='9J6zG'><tfoot id='9J6zG'></tfoot><dl id='9J6zG'><fieldset id='9J6zG'></fieldset></dl></div>

          <small id='9J6zG'></small><noframes id='9J6zG'>

                <tbody id='9J6zG'></tbody>

            • <legend id='9J6zG'><style id='9J6zG'><dir id='9J6zG'><q id='9J6zG'></q></dir></style></legend>

                  本文介绍了如何从 0000 循环到 9999 并将数字转换为相对字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想得到一些字符串,范围从0000到9999,也就是说,我想打印以下字符串:

                  i want to get some string, range from 0000 to 9999, that's to say, i want to print the following string:

                  0000
                  0001
                  0002
                  0003
                  0004
                  0005
                  0006
                  ....
                  9999
                  

                  我尝试使用 print " ".join([str(num) for num in range(0, 9999)]),但失败了,我得到以下数字:

                  i tried to use print " ".join([str(num) for num in range(0, 9999)]), but failed, i get the following number:

                  0
                  1
                  2
                  3
                  4
                  5
                  6
                  ...
                  9999
                  

                  我希望python自动添加前缀0,使数字保持4位数字时间.谁能帮帮我?任何帮助表示赞赏.

                  i want python to add the prefix 0 automatically, making the number remain 4 bit digits all the time. can anyone give a hand to me? any help appreciated.

                  推荐答案

                  获得所需内容的一种方法是使用字符串格式:

                  One way to get what you want is to use string formatting:

                  >>> for i in range(10):
                  ...     '{0:04}'.format(i)
                  ... 
                  '0000'
                  '0001'
                  '0002'
                  '0003'
                  '0004'
                  '0005'
                  '0006'
                  '0007'
                  '0008'
                  '0009'
                  

                  所以要做你想做的,这样做:

                  So to do what you want, do this:

                  print("
                  ".join(['{0:04}'.format(num) for num in range(0, 10000)]))
                  

                  这篇关于如何从 0000 循环到 9999 并将数字转换为相对字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

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

                    • <tfoot id='1hAIn'></tfoot>
                    • <small id='1hAIn'></small><noframes id='1hAIn'>

                            <tbody id='1hAIn'></tbody>
                        1. <legend id='1hAIn'><style id='1hAIn'><dir id='1hAIn'><q id='1hAIn'></q></dir></style></legend>

                            <bdo id='1hAIn'></bdo><ul id='1hAIn'></ul>