string.ljust(len,str)字符向左对齐,用str补齐长度
string.rjust(len,str)字符向右对齐,用str补齐长度
string.center(len,str)字符中间对齐,用str补齐长度
string.zfill(width)指定字符串长度,右对齐,前面补充0
print 'bbb'.ljust(10,'a')
输出:bbbaaaaaaa
print 'bbb'.rjust(10,'a')
输出:aaaaaaabbb
print 'bbb'.center(10,'a')
输出:aaabbbaaaa
print '2'.zfill(5)
输出:00002
'''
原字符串左侧对齐, 右侧补零:
'''
str.ljust(width,'0')
input: '789'.ljust(32,'0')
output: '78900000000000000000000000000000'
'''
原字符串右侧对齐, 左侧补零:
方法一:
'''
str.rjust(width,'0')
input: '798'.rjust(32,'0')
output: '00000000000000000000000000000798'
'''
方法二:
'''
str.zfill(width)
input: '123'.zfill(32)
output:'00000000000000000000000000000123'
'''
方法三:
'''
'%07d' % n
input: '%032d' % 89
output:'00000000000000000000000000000089'