<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          字符串對齊的常用方法

          共 3179字,需瀏覽 7分鐘

           ·

          2021-05-21 02:26

          你好,我是 zhenguo 今天這篇文章匯總一些關(guān)于字符串對齊的常用方法。

          1 左對齊字符串

          # 1 左對齊字符串
          # 使得總長度為 20
          In [2]: text = 'Hello World'         ```                                 
          In [3]: text.ljust(20)                     
          Out[3]: 'Hello World         '

          2 右對齊字符串

          # 2 右對齊字符串
          # 使得總長度為 20 
          In [6]: text.rjust(20)                 
          Out[6]: '         Hello World'

          3 中間對齊字符串

          # 3 中間對齊字符串
          # 使得總長度為 20 

          In [7]: text.center(20)                   
          Out[7]: '    Hello World     '

          4 右對齊字符串

          # 4 右對齊字符串
          # 使得總長度為 20 

          In [8]: format(text, '>20')                             
          Out[8]: '         Hello World'

          5 左對齊字符串

          # 5 左對齊字符串
          # 使得總長度為 20 
          In [10]: format(text, '<20')                        
          Out[10]: 'Hello World         '

          6 中間對齊字符串

          # 6 中間對齊字符串
          # 使得總長度為 20 
          In [11]: format(text, '^20')                      
          Out[11]: '    Hello World     '

          7 中間對齊字符串,并用-填充

          # 7 中間對齊字符串,并用-填充
          # 使得總長度為 20  
          In [12]: format(text, '-^20')       
          Out[12]: '----Hello World-----'

          8 每行固定顯示10個字符

          # 8 每行固定顯示10個字符

          In [21]: s="""我是安裝nlp包 corpy, 
              ...: 服務(wù)器是騰訊Ubuntu 18.04 , 
              ...: 使用 pip 安裝優(yōu)先走騰訊index源, 
              ...: 很遺憾安裝到中間,安裝依賴包 ufdl.udpipe """

              
          In [15]: import textwrap
          In [23]: print(textwrap.fill(s, 10)) 
          我是安裝nlp包
          corpy, 服務(wù)器
          是騰訊Ubuntu
          18.04 , 使用
          pip 安裝優(yōu)先走騰
          訊index源, 很
          遺憾安裝到中間,安裝
          依賴包 ufdl.u
          dpipe

          9 基于上面這些方法,能夠?qū)崿F(xiàn)我的第一個 Python 小項目,開放完整代碼 里的KWIC顯示,感興趣的可以看看。

          10 你還可以訂閱話題 Python 真經(jīng),里面已經(jīng)有92篇我寫過的Python類文章,歡迎學(xué)習(xí)。

          瀏覽 29
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  av毛片网站 | 青娱乐免费视频一二三 | 大香蕉操逼| 日韩激情小说 | 人人前后碰 |