首页 > 编程语言 >python 字符串 格式化输出 槽格式 左中右对齐的内容

python 字符串 格式化输出 槽格式 左中右对齐的内容

时间:2023-03-01 23:32:39浏览次数:57  
标签:20 填充 format python 左中右 格式 print 对齐

"""
槽的格式限定
冒号:左边填序号或名称,右边填写格式
"""
# 右对齐的字符串,宽度为20
s1 = "{:>20}".format("hello")
print(s1)

# 右对齐,宽20,!填充
s2 = "{:!>20}".format("python")
print(s2)

# 左对齐,宽30,¥填充
s3 = "{:¥<30}".format("money")
print(s3)

# 居中对齐,宽20,*填充
s4 = "{:*^20}".format("left")
print(s4)

标签:20,填充,format,python,左中右,格式,print,对齐
From: https://blog.51cto.com/u_13137233/6094384

相关文章