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://codercto.com/courses/l/8.html

查看所有标签

Advanced Web Metrics with Google Analytics

Advanced Web Metrics with Google Analytics

Brian Clifton / Sybex / 2008 / USD 39.99

Are you getting the most out of your website? Google insider and web metrics expert Brian Clifton reveals the information you need to get a true picture of your site's impact and stay competitive usin......一起来看看 《Advanced Web Metrics with Google Analytics》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

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

URL 编码/解码