python str方法之ljust、rjust、center

# -*- coding: cp936 -*-
#python 27
#xiaodeng
#str方法之ljust、rjust、center
#http://www.runoob.com/python/att-string-rjust.html



'''
语法:
str.rjust(width[, fillchar])
参数:
width -- 指定填充指定字符后中字符串的总长度.
fillchar -- 填充的字符,默认为空格。
'''

#ljust左对齐
str='xiaodeng'
print str.ljust(20,'-')#使用短横线做填充

#rjust右对齐
print str.rjust(20,'-')

#center居中对齐
print str.center(20,'-')
原文地址:https://www.cnblogs.com/dengyg200891/p/5015201.html