Python3 string.ljust()方法

ljust()方法返回以长度(width)向左对齐的字符串。填充值是使用指定fillchar(默认为空格)完成的。如果宽度小于 len(s)则返回原始字符串。

语法

以下是 ljust()方法的语法 -
str.ljust(width[, fillchar])

参数

  • width -- 在填充后总字符串的长度

  • fillchar --这是填充符,默认是空格

返回值

此方法返回长度(width)向左对齐的字符串。填充值是使用指定fillchar(默认为空格)完成的。如果宽度小于 len(s)则返回原始字符串。

示例

下面的示例显示 ljust()方法的使用。
#!/usr/bin/python3

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

print str.ljust(50, '*')
当我们运行上面的程序,会产生以下结果 -
this is string example....wow!!!******************

上一篇: Python3数字 下一篇: Python3字符串