Python3 center()方法

Python 3 教程 · 2019-02-05 19:27:00

center() 方法返回一个指定的宽度 width 居中的字符串,fillchar 为填充的字符,默认为空格。

语法

center()方法语法:

str.center(width[, fillchar])

参数

  • width -- 字符串的总宽度。
  • fillchar -- 填充字符。

返回值

返回一个指定的宽度 width 居中的字符串,如果 width 小于字符串宽度直接返回字符串,否则使用 fillchar 去填充。

实例

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

#!/usr/bin/python3

str = "[www.codercto.com]"

print ("str.center(40, '*') : ", str.center(40, '*'))

以上实例输出结果如下:

str.center(40, '*') :  ************[www.codercto.com]************

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Understanding Computation

Understanding Computation

Tom Stuart / O'Reilly Media / 2013-6-3 / USD 39.99

Finally, you can learn computation theory and programming language design in an engaging, practical way. Understanding Computation explains theoretical computer science in a context you'll recognize, ......一起来看看 《Understanding Computation》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具