Python的 ljust()方法向左对齐字符串,并用fillchars填充其余空间。此方法返回一个左对齐的新字符串,并用fillchars填充。
ljust(width[, fillchar])
它返回左对齐的字符串。
让无涯教程看一些ljust()方法的例子来了解它的功能。
链接:https://www.learnfk.comhttps://www.learnfk.com/python3/python-string-ljust-method.html
来源:LearnFk无涯教程网
# Python ljust() method example # 变量声明 str = 'Learnfk' # 函数调用 str = str.ljust(20) # 显示结果 print(str)
输出:
L | e | a | r | n | f | k |
# Python ljust() method example # 变量声明 str = 'Learnfk' # 函数调用 str = str.ljust(15,"$") # 显示结果 print(str)
输出:
L | e | a | r | n | f | k | $ | $ | $ | $ | $ | $ | $ | $ |
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)