python print 左对齐
发布网友
发布时间:2022-04-22 01:40
我来回答
共1个回答
热心网友
时间:2023-09-18 10:52
>>> items = [
... ('data collector', 'OK'),
... ('prepair', 'Warning'),
... ('bind datas', 'Error'),
... ('output report', 'Fail'),
... ]
>>> fmt = '%40s %-9s'
>>> print '\n'.join([fmt % x for x in items])
data collector OK
prepair Warning
bind datas Error
output report Fail
>>> fmt = '%-40s %9s'
>>> print '\n'.join([fmt % x for x in items])
data collector OK
prepair Warning
bind datas Error
output report Fail
>>> print '\n'.join([fmt % (x, '[%s]'%y) for x, y in items])
data collector [OK]
prepair [Warning]
bind datas [Error]
output report [Fail]
>>>