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

    <tfoot id='SkONg'></tfoot>

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

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

        如何在 Python 中用空格将字符串填充到固定长度?

        时间:2023-06-06
        <legend id='rLUh5'><style id='rLUh5'><dir id='rLUh5'><q id='rLUh5'></q></dir></style></legend>
          <tbody id='rLUh5'></tbody>
      1. <tfoot id='rLUh5'></tfoot>

            • <bdo id='rLUh5'></bdo><ul id='rLUh5'></ul>

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

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

                  本文介绍了如何在 Python 中用空格将字符串填充到固定长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我确信这在很多地方都有介绍,但我不知道我正在尝试执行的操作的确切名称,所以我无法真正查找它.我已经阅读了 30 分钟的官方 Python 书籍,试图找出如何做到这一点.

                  I'm sure this is covered in plenty of places, but I don't know the exact name of the action I'm trying to do so I can't really look it up. I've been reading an official Python book for 30 minutes trying to find out how to do this.

                  问题:我需要在一定长度的字段"中放入一个字符串.

                  Problem: I need to put a string in a certain length "field".

                  例如,如果姓名字段有 15 个字符长,而我的名字是 John,我会得到John"后跟 11 个空格来创建 15 个字符的字段.

                  For example, if the name field was 15 characters long, and my name was John, I would get "John" followed by 11 spaces to create the 15 character field.

                  我需要它适用于为变量name"输入的任何字符串.

                  I need this to work for any string put in for the variable "name".

                  我知道这可能是某种形式的格式,但我找不到执行此操作的确切方法.帮助将不胜感激.

                  I know it will likely be some form of formatting, but I can't find the exact way to do this. Help would be appreciated.

                  推荐答案

                  这是超级简单的format:

                  >>> a = "John"
                  >>> "{:<15}".format(a)
                  'John           '
                  

                  这篇关于如何在 Python 中用空格将字符串填充到固定长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:带有 SQL 通配符和 LIKE 的 Python 字符串格式 下一篇:将两个列表加入格式化字符串的最聪明方法

                  相关文章

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

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

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