python 4-5如何对字符串进行左, 右, 居中对齐

字符串对齐使用ljust,ojust,center或者format的’<‘’>’’^’三个字符

s = 'abd'
s.ljust(10, '_')
s.rjust(10, '_')
s.center(10, '_')
format(s, '<10')
format(s, '>10')
format(s, '^10')

d ={'a':100,'adb3dd':9,'lof':3444}
map(len, d.keys())
list(map(len, d.keys()))
k = max(map(len, d.keys()))
for x in d:
      print(x.ljust(k), ':', d[x])
rmax = max(map(len, [str(x) for x in d.values()]))
rmax
for x in d:
     print(x.ljust(k), ':', str(d[x]).rjust(rmax))