中国最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2

python教程

  • Python 入门教程
  • Python 基础教程

    Python 高级教程

    Python 常用资源

    Python 拓展阅读

    python文本 字符串对齐

    阅读 (2256)

    python 字符串对齐

    场景:

    字符串对齐

    python提供非常容易的方法,使得字符串对齐

      >>> print("abc".center (30,'-'))  
      -------------abc--------------                         
      >>> print("abc".ljust (30)+'|')  
      abc                           |  
      >>> print("abc".rjust (30))  
                                 abc  
      >>>   
    

    分别是center,ljust,rjust

    三个方法默认填充是空格,也可以使用其他字符填充

    关闭
    程序员人生