python字符串对齐与填充
s = "abc"
# 从左到右填充:abc*****
# 从右到左填充:*****abc
# 从中间向两边填充:**abc***
# 方法1
print(s.ljust(8, "*"))
print(s.rjust(8, "*"))
print(s.center(8, "*"))
# 方法2
print(format(s, "*<8"))
print(format(s, "*>8"))
print(format(s, "*^8"))
s = "abc"
# 从左到右填充:abc*****
# 从右到左填充:*****abc
# 从中间向两边填充:**abc***
# 方法1
print(s.ljust(8, "*"))
print(s.rjust(8, "*"))
print(s.center(8, "*"))
# 方法2
print(format(s, "*<8"))
print(format(s, "*>8"))
print(format(s, "*^8"))