Python rjust()方法

Python 教程 · 2019-02-02 16:58:35

描述

Python rjust() 返回一个原字符串右对齐,并使用空格填充至长度 width 的新字符串。如果指定的长度小于字符串的长度则返回原字符串。

语法

rjust()方法语法:

str.rjust(width[, fillchar])

参数

  • width -- 指定填充指定字符后中字符串的总长度.
  • fillchar -- 填充的字符,默认为空格。

返回值

返回一个原字符串右对齐,并使用空格填充至长度 width 的新字符串。如果指定的长度小于字符串的长度则返回原字符串

实例

以下实例展示了rjust()函数的使用方法:

#!/usr/bin/python

str = "this is string example....wow!!!";

print str.rjust(50, '0');

以上实例输出结果如下:

000000000000000000this is string example....wow!!!

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

查看所有标签

Purely Functional Data Structures

Purely Functional Data Structures

Chris Okasaki / Cambridge University Press / 1999-6-13 / USD 49.99

Most books on data structures assume an imperative language such as C or C++. However, data structures for these languages do not always translate well to functional languages such as Standard ML, Ha......一起来看看 《Purely Functional Data Structures》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

html转js在线工具
html转js在线工具

html转js在线工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具