介绍Python中方法ljust(),rjust(),center()和zfill()

s=“abcde”

在这里插入图片描述

ljust()

左对齐,不满50位的数用0补充;

s="abcde"
print s.ljust(50,'0')

在这里插入图片描述

rjust(),右对齐

center(),中间对齐

S.zfill(width) #把S变成width长,并在右对齐,不足部分用0补足

猜你喜欢

转载自blog.csdn.net/weixin_45556441/article/details/115058148