内容简介:Python center() 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串。默认填充字符为空格。
描述
Python center() 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串。默认填充字符为空格。
语法
center()方法语法:
str.center(width[, fillchar])
参数
- width -- 字符串的总宽度。
- fillchar -- 填充字符。
返回值
该方法返回一个原字符串居中,并使用空格填充至长度 width 的新字符串。
实例
以下实例展示了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
以上所述就是小编给大家介绍的《Python center()方法》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Effective Engineer
Edmond Lau / The Effective Bookshelf, Palo Alto, CA. / 2015-3-19 / USD 39.00
Introducing The Effective Engineer — the only book designed specifically for today's software engineers, based on extensive interviews with engineering leaders at top tech companies, and packed with h......一起来看看 《The Effective Engineer》 这本书的介绍吧!