Python center()方法

Python 教程 · 2019-02-02 09:42:29

描述

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

语法

center()方法语法:

str.center(width[, fillchar])

参数

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

返回值

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

实例

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

>>>str = 'codercto' >>> str.center(20, '*') '*******codercto*******' >>> str.center(20) ' codercto ' >>>

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

查看所有标签

JavaScript

JavaScript

David Flanagan / O'Reilly Media / 2011-5-13 / GBP 39.99

The book is a programmer's guide and comprehensive reference to the core JavaScript language and to the client-side JavaScript APIs defined by web browsers. The sixth edition covers HTML 5 and ECMA......一起来看看 《JavaScript》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

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

HEX HSV 互换工具