1、
>>> a = "good" >>> a.ljust(1) 'good' >>> a.ljust(10) ## 左对齐 'good ' >>> a.ljust(10,"-") ## 左对齐,以-填充多余宽度 'good------' >>> a.ljust(20,"x") 'goodxxxxxxxxxxxxxxxx' >>> a 'good' >>> a.center(2) 'good' >>> a.center(10) ## 中间对齐 ' good ' >>> a.center(10,"x") 'xxxgoodxxx' >>> a.rjust(3) 'good' >>> a.rjust(10) ##右对齐 ' good' >>> a.rjust(10,"y") 'yyyyyygood'