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中按可变长度格式化

        Format in python by variable length(在python中按可变长度格式化)

          <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中按可变长度格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                  Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                  How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                  Centering an object in Kivy(在 Kivy 中将对象居中)
                  How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                  Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)
                  1. <tfoot id='l4K6v'></tfoot>
                      <tbody id='l4K6v'></tbody>
                      <bdo id='l4K6v'></bdo><ul id='l4K6v'></ul>
                    • <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>