【python】字符串对齐补位

1. 字符串补位 左右中 对齐

str1 = 'space'
str1.ljust(10, '-')  # 左对齐
'space-----'
str1.rjust(10, '-')  # 右对齐
'-----space'
str1.center(10, '-')  # 居中对齐
'--space---'

2. 字符串补零

str2 = '123'
str2.zfill(5)
'00123'
posted @ 2022-04-12 15:45  是阿杰呀  阅读(697)  评论(0)    收藏  举报