Python 字符串左对齐填充:使用 ljust() 方法
你可以使用字符串的 ljust() 方法来填充异常。例如:
s = 'hello'
width = 10
filled_str = s.ljust(width, '*')
print(filled_str)
输出:
hello*****
在这个例子中,ljust() 方法将字符串填充到指定的宽度,使用 '*' 字符进行填充。
原文地址: https://www.cveoy.top/t/topic/mtSZ 著作权归作者所有。请勿转载和采集!