Python 3 教程
ljust() 方法返回一個原字符串左對齊,并使用空格填充至指定長度的新字符串。如果指定的長度小于原字符串的長度則返回原字符串。
ljust()方法語法:
str.ljust(width[, fillchar])
返回一個原字符串左對齊,并使用空格填充至指定長度的新字符串。如果指定的長度小于原字符串的長度則返回原字符串。
以下實例展示了ljust()的使用方法:
#!/usr/bin/python3 str = "Runoob example....wow!!!" print (str.ljust(50, '*'))
以上實例輸出結(jié)果如下:
Runoob example....wow!!!**************************