您的位置:首页 > 编程语言 > Python开发

python 格式化输出

2013-12-18 18:43 176 查看

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*****'

'======================待续======================'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: