发布于 2015-06-21 10:38:07 | 124 次阅读 | 评论: 0 | 来源: 网络整理

center()方法返回集中在长度宽度的字符串。填充是通过使用specifiedfillchar。默认填充字符是一个空格。

语法

以下是center()方法的语法:


str.center(width[, fillchar])

参数

  • 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
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务