ljust()將字符串左對齊右側填充
rjust()將字符串右對齊左側填充
舉個例子:
1 a = "hello world" 2 a1 = a.ljust(15, "*") 3 print(a1)
輸出結果:
hello world****
我們定義了總長度為15,將字符串左對齊,剩余的右側以*填充
1 b = "hello world" 2 b1 = b.rjust(15, "_") 3 print(b1)
輸出結果:
____hello world
我們定義了總長度為15,將字符串右對齊,剩余的左側以_填充