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

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

    • <bdo id='xKZox'></bdo><ul id='xKZox'></ul>
      <tfoot id='xKZox'></tfoot>

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

        在 Python 中的數字列表中添加前導零

        add leading zeros to a list of numbers in Python(在 Python 中的數字列表中添加前導零)
            <bdo id='loeAn'></bdo><ul id='loeAn'></ul>

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

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

                  <tbody id='loeAn'></tbody>

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

                  本文介紹了在 Python 中的數字列表中添加前導零的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我是 Python 新手.我正在嘗試調整列表的格式,如下所示:

                  I am new to Python. I am trying to adjust the format of a list which looks like below:

                  data=[1,10,313,4000,51234,123456]
                  

                  我想將它們轉換為帶有前導零的字符串列表:

                  and I would like to convert them to a list of strings with leading zeros:

                  result=['000001','000010','000313','004000','051234','123456']
                  

                  每個元素都有 6 個數字.

                  each of the element has 6 digits.

                  我知道一個數字 X,我可以做到:

                  I know for a single number X, I can do:

                  str(X).zfill(6)
                  

                  但我不確定如何將其應用于列表.我想在不使用 for 循環的情況下解決這個問題.

                  but I am not sure how to apply this to a list. I would like to solve this problem without using a for loop.

                  有人可以幫忙嗎?謝謝.

                  Anyone could help? Thanks.

                  推薦答案

                  應用相同zfill函數,像這樣

                  Apply the same zfill function in a list comprehension, like this

                  >>> [str(item).zfill(6) for item in data]
                  ['000001', '000010', '000313', '004000', '051234', '123456']
                  

                  或者,您可以使用字符串的 format方法,使用格式說明符,像這樣

                  Alternatively, you can use the string's format method, with format specifiers, like this

                  >>> ["{:06d}".format(item) for item in data]
                  ['000001', '000010', '000313', '004000', '051234', '123456']
                  

                  如果您要更頻繁地進行格式化,則可以將其存儲在變量中,如下所示

                  If you are going to do the formatting more often, then you can store that in a variable, like this

                  >>> formatter = "{:06d}".format
                  >>> [formatter(item) for item in data]
                  ['000001', '000010', '000313', '004000', '051234', '123456']
                  

                  如果您使用的是 Python 2.x,那么您可以使用 mapformatter 函數,像這樣

                  If you are using Python 2.x, then you can use map and the formatter function, like this

                  >>> map(formatter, data)
                  ['000001', '000010', '000313', '004000', '051234', '123456']
                  

                  如果您使用的是 Python 3.x,map返回一個可迭代的 map 對象.所以,你需要顯式地創建一個列表,像這樣

                  If you are using Python 3.x, map returns an iterable map object. So, you need to explicitly create a list, like this

                  >>> list(map(formatter, data))
                  ['000001', '000010', '000313', '004000', '051234', '123456']
                  

                  這篇關于在 Python 中的數字列表中添加前導零的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 自動更改角色顏色)
                  <legend id='NY4ns'><style id='NY4ns'><dir id='NY4ns'><q id='NY4ns'></q></dir></style></legend>

                      <tbody id='NY4ns'></tbody>
                        • <small id='NY4ns'></small><noframes id='NY4ns'>

                          • <bdo id='NY4ns'></bdo><ul id='NY4ns'></ul>
                            <tfoot id='NY4ns'></tfoot>
                            <i id='NY4ns'><tr id='NY4ns'><dt id='NY4ns'><q id='NY4ns'><span id='NY4ns'><b id='NY4ns'><form id='NY4ns'><ins id='NY4ns'></ins><ul id='NY4ns'></ul><sub id='NY4ns'></sub></form><legend id='NY4ns'></legend><bdo id='NY4ns'><pre id='NY4ns'><center id='NY4ns'></center></pre></bdo></b><th id='NY4ns'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NY4ns'><tfoot id='NY4ns'></tfoot><dl id='NY4ns'><fieldset id='NY4ns'></fieldset></dl></div>
                            主站蜘蛛池模板: 免费观看黄a一级视频 | 伊人久久综合影院 | 日韩在线h | 日韩 欧美 二区 | 综合久久99 | 99精品99 | 欧美4p| 一级欧美一级日韩片免费观看 | 日韩欧美精品 | 国产一区不卡 | 欧美精品一区二区三区在线 | 成人一级视频在线观看 | 精品国产高清一区二区三区 | 91视频在线观看免费 | 久久久亚洲一区 | 2021天天躁夜夜看 | 成人激情视频在线观看 | 国产精品视频一二三区 | 夏同学福利网 | 99这里只有精品视频 | 永久看片 | 中文字幕在线剧情 | 中文字幕一区二区三区在线视频 | 视频一区二区三区在线观看 | 亚洲视频一区在线 | 四虎影院免费在线 | av香港经典三级级 在线 | 久久久久久黄 | 色综合久久天天综合网 | 日本一区二区高清不卡 | 欧美在线视频一区二区 | 四虎影视免费在线 | 国际精品久久 | 国产日韩欧美 | 欧美成人不卡 | 成年女人免费v片 | 亚洲国产成人精品久久久国产成人一区 | 久久久欧洲 | 99久久久久 | 97超级碰碰 | 欧美在线视频二区 |