Python center()返回以长度和宽度为中心的字符串。填充是使用指定的填充字符完成的。默认填充符是空格。
center(width, fillchar) - 语法
str.center(width[, fillchar])
width - 这是字符串的总宽度。
fillchar - 这是填充字符。
center(width, fillchar) - 返回值
此方法返回以长度和宽度组成的字符串的中心。
center(width, fillchar) - 示例
以下示例显示center()方法的用法。
#!/usr/bin/python str="this is string example....wow!!!" print "str.center(40, a) : ", str.center(40, a)
运行上面代码输出
str.center(40, a) : aaaathis is string example....wow!!!aaaa