Python ljust()方法

Python 教程 · 2019-02-02 14:29:47

描述

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

语法

ljust()方法语法:

str.ljust(width[, fillchar])

参数

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

返回值

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

实例

以下实例展示了ljust()的使用方法:

#!/usr/bin/python

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

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

以上实例输出结果如下:

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

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

查看所有标签

The Nature of Code

The Nature of Code

Daniel Shiffman / The Nature of Code / 2012-12-13 / GBP 19.95

How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital w......一起来看看 《The Nature of Code》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试