教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 Python center()方法

Python center()方法

发布时间:2021-12-11   编辑:jiaochengji.com
教程集为您提供Python center()方法等资源,欢迎您收藏本站,我们将为您提供最新的Python center()方法资源

描述

Python center() 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串。默认填充字符为空格。

语法

center()方法语法:

<pre class="brush:html;toolbar:false">string.center(width[, fillchar])</pre>

参数

width -- 字符串的总宽度。

fillchar -- 填充字符。

返回值

该方法返回一个原字符串居中,并使用空格填充至长度 width 的新字符串。

实例

以下实例展示了center()方法的实例:

<pre class="brush:html;toolbar:false">#!/usr/bin/python   string = "this is string example....wow!!!";   print "string.center(40, 'a') : ", string.center(40, 'a')</pre>

以上实例输出结果如下:

<pre class="brush:html;toolbar:false">string.center(40, 'a') :  aaaathis is</pre>

<span style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
</span>

您可能感兴趣的文章:
找不到python安装路径怎么办
python 如何向上取整
linux如何看Python版本
Python center()方法
python中len是什么
python的类的方法为什么有个self
python为什么要用self
python 函数和方法的区别有哪些
python 如何表示大写字母
python控制台是什么意思

上一篇:Python find()方法 下一篇:Python encode()方法
[关闭]
~ ~