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

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

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

        <tfoot id='UEZEM'></tfoot>
          <bdo id='UEZEM'></bdo><ul id='UEZEM'></ul>

        在python中按可变长度格式化

        时间:2023-06-06

          <legend id='s4zm8'><style id='s4zm8'><dir id='s4zm8'><q id='s4zm8'></q></dir></style></legend>
            <tbody id='s4zm8'></tbody>

              <bdo id='s4zm8'></bdo><ul id='s4zm8'></ul>

                • <tfoot id='s4zm8'></tfoot>

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

                • <i id='s4zm8'><tr id='s4zm8'><dt id='s4zm8'><q id='s4zm8'><span id='s4zm8'><b id='s4zm8'><form id='s4zm8'><ins id='s4zm8'></ins><ul id='s4zm8'></ul><sub id='s4zm8'></sub></form><legend id='s4zm8'></legend><bdo id='s4zm8'><pre id='s4zm8'><center id='s4zm8'></center></pre></bdo></b><th id='s4zm8'></th></span></q></dt></tr></i><div id='s4zm8'><tfoot id='s4zm8'></tfoot><dl id='s4zm8'><fieldset id='s4zm8'></fieldset></dl></div>
                  本文介绍了在python中按可变长度格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想使用 .format() 方法打印类似楼梯的图案.我试过了,

                  I want to print a staircase like pattern using .format() method. I tried this,

                  for i in range(6, 0, -1):
                      print("{0:>"+str(i)+"}".format("#"))
                  

                  但它给了我以下错误:

                  ValueError: Single '}' encountered in format string
                  

                  基本上这个想法是打印

                       #
                      #
                     #
                    #
                   #
                  #
                  

                  代码看起来类似于,

                  for i in range(6, 0, -1):
                      print("{0:>i}".format("#"))
                  

                  推荐答案

                  目前你的代码解释如下:

                  Currently your code interpreted as below:

                  for i in range(6, 0, -1):
                      print ( ("{0:>"+str(i))     +     ("}".format("#")))
                  

                  所以格式字符串由单个}"构成,这是不正确的.您需要以下内容:

                  So the format string is constructed of a single "}" and that's not correct. You need the following:

                  for i in range(6, 0, -1):
                      print(("{0:>"+str(i)+"}").format("#"))
                  

                  随心所欲地工作:

                  ================ RESTART: C:/Users/Desktop/TES.py ================
                       #
                      #
                     #
                    #
                   #
                  #
                  >>> 
                  

                  这篇关于在python中按可变长度格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在python中显示区域设置敏感时间格式而无需秒 下一篇:Python3 - 在字符串格式化程序参数中使用变量

                  相关文章

                  1. <tfoot id='l4K6v'></tfoot>
                    • <bdo id='l4K6v'></bdo><ul id='l4K6v'></ul>
                  2. <legend id='l4K6v'><style id='l4K6v'><dir id='l4K6v'><q id='l4K6v'></q></dir></style></legend>

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

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