str.center
string的center方法返回以指定长度为宽度的居中字符串,使用指定字符填充,默认使用空格填充;
语法
str.center(width[,fillchar])
- 参数:width - 字符串的总宽度
fillchar - 填充的字符 - 返回值:更新后的居中字符串
示例
str = "hello"
print("str.center(10) : ",str.center(10))
print("str.center(10,'-'): ",str.center(10,'-'))
执行结果
str.center(10) : hello
str.center(10,'-'): --hello---