久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='oMwJI'></small><noframes id='oMwJI'>

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

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

        Python3 - 在字符串格式化程序參數中使用變量

        Python3 - Use a variables inside string formatter arguments(Python3 - 在字符串格式化程序參數中使用變量)
      2. <i id='d8EFL'><tr id='d8EFL'><dt id='d8EFL'><q id='d8EFL'><span id='d8EFL'><b id='d8EFL'><form id='d8EFL'><ins id='d8EFL'></ins><ul id='d8EFL'></ul><sub id='d8EFL'></sub></form><legend id='d8EFL'></legend><bdo id='d8EFL'><pre id='d8EFL'><center id='d8EFL'></center></pre></bdo></b><th id='d8EFL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='d8EFL'><tfoot id='d8EFL'></tfoot><dl id='d8EFL'><fieldset id='d8EFL'></fieldset></dl></div>
          <tbody id='d8EFL'></tbody>
          <tfoot id='d8EFL'></tfoot>

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

          <legend id='d8EFL'><style id='d8EFL'><dir id='d8EFL'><q id='d8EFL'></q></dir></style></legend>

                • <bdo id='d8EFL'></bdo><ul id='d8EFL'></ul>
                  本文介紹了Python3 - 在字符串格式化程序參數中使用變量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在打印一些格式化的列.我想使用以下變量來設置我的 .format 參數中的長度

                  I have some formatted columns that I'm printing. I would like to use the following variables to set the lengths in my .format arguments

                  number_length = 5
                  name_length = 24
                  viewers_length = 9
                  

                  我有

                  print('{0:<5}{1:<24}{2:<9}'.format(' #','channel','viewers'), end = '')
                  

                  理想情況下,我想要類似的東西

                  Ideally I would like something like

                  print('{0:<number_length}{1:<name_length}{2:<viewers_length}'.format(
                       ' #','channel','viewers'), end = '')
                  

                  但這給了我一個無效的字符串格式化錯誤.

                  But this gives me an invalid string formatter error.

                  我曾嘗試在變量和括號前加上 %,但沒有成功.

                  I have tried with % before the variables and parenthesis, but have had no luck.

                  推薦答案

                  你需要:

                  1. 也將名字用大括號括起來;和
                  2. 將寬度作為關鍵字參數傳遞給 str.format.

                  例如:

                  >>> print("{0:>{number_length}}".format(1, number_length=8))
                         1
                  

                  你也可以使用字典解包:

                  You can also use dictionary unpacking:

                  >>> widths = {'number_length': 8}
                  >>> print("{0:>{number_length}}".format(1, **widths))
                         1
                  

                  str.format 不會在本地范圍內查找適當的名稱;它們必須顯式傳遞.

                  str.format won't look in the local scope for appropriate names; they must be passed explicitly.

                  對于您的示例,這可以像這樣工作:

                  For your example, this could work like:

                  >>> widths = {'number_length': 5,
                                'name_length': 24,
                                'viewers_length': 9}
                  >>> template= '{0:<{number_length}}{1:<{name_length}}{2:<{viewers_length}}'
                  >>> print(template.format('#', 'channel', 'visitors', end='', **widths))
                  #    channel                 visitors
                  

                  (請注意,end 和任何其他顯式關鍵字參數必須在 **widths 之前.)

                  (Note that end, and any other explicit keyword arguments, must come before **widths.)

                  這篇關于Python3 - 在字符串格式化程序參數中使用變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                • <i id='JRKXG'><tr id='JRKXG'><dt id='JRKXG'><q id='JRKXG'><span id='JRKXG'><b id='JRKXG'><form id='JRKXG'><ins id='JRKXG'></ins><ul id='JRKXG'></ul><sub id='JRKXG'></sub></form><legend id='JRKXG'></legend><bdo id='JRKXG'><pre id='JRKXG'><center id='JRKXG'></center></pre></bdo></b><th id='JRKXG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JRKXG'><tfoot id='JRKXG'></tfoot><dl id='JRKXG'><fieldset id='JRKXG'></fieldset></dl></div>

                        <tbody id='JRKXG'></tbody>

                    • <small id='JRKXG'></small><noframes id='JRKXG'>

                        <tfoot id='JRKXG'></tfoot>
                          <bdo id='JRKXG'></bdo><ul id='JRKXG'></ul>
                          <legend id='JRKXG'><style id='JRKXG'><dir id='JRKXG'><q id='JRKXG'></q></dir></style></legend>
                            主站蜘蛛池模板: 免费天天干 | 日韩成年人视频在线 | 国产精品久久久久久久一区探花 | 国产精品视频不卡 | 网站黄色在线免费观看 | 日韩一区二区三区精品 | 特级特黄特色的免费大片 | 午夜日韩| 色资源在线 | 美女国内精品自产拍在线播放 | 伊人超碰在线 | 一区二区av | 一区二区三区四区在线 | 91国自视频 | 麻豆视频国产在线观看 | 日韩一二三区 | 亚洲人a | 精品国产aⅴ | 中文字幕亚洲精品在线观看 | 亚洲二区在线 | 欧美国产日韩精品 | 91在线看片| 国产一区二区三区视频 | 蜜桃一区| 免费在线a视频 | 成年人在线观看视频 | 久久久久亚洲精品 | 日韩免费视频一区二区 | 成人九色| 91久久久精品国产一区二区蜜臀 | 亚洲免费观看视频网站 | 精品一区二区电影 | 久久久高清 | 青青操av | 仙人掌旅馆在线观看 | 久久久久国产一区二区三区四区 | 玖玖玖在线 | av色在线| 日本精品国产 | 美女爽到呻吟久久久久 | 亚洲国产一区二区三区在线观看 |