python 格式化输出

来源:互联网 发布:网络测线仪 编辑:程序博客网 时间:2024/05/17 02:30
  • string的格式化输出方式

第一种方式:format函数

  a="hello world"

  format(a,"*^20")

  输出:****hello world*****

第二种方式: %

'%-20s' % a或者 '%20s' % a


第三种方式: ljust,rjust函数

>>> text.rjust(20,'=')
'=========Hello World'
>>> text.center(20,'*')
'****Hello World*****'

'======================待续======================'

0 0