首页 > 编程语言 > 详细

python中指定字符串宽度,并指定填充字符串

时间:2021-02-25 15:17:56      阅读:70      评论:0      收藏:0      [点我收藏+]

 

1、

>>> a = "good"
>>> a.ljust(1)
good
>>> a.ljust(10)   ## 左对齐
good      
>>> a.ljust(10,"-")  ## 左对齐,以-填充多余宽度
good------
>>> a.ljust(20,"x")
goodxxxxxxxxxxxxxxxx
>>> a
good
>>> a.center(2)
good
>>> a.center(10)  ## 中间对齐
   good   
>>> a.center(10,"x")
xxxgoodxxx
>>> a.rjust(3)
good
>>> a.rjust(10)   ##右对齐
      good
>>> a.rjust(10,"y")
yyyyyygood

 

python中指定字符串宽度,并指定填充字符串

原文:https://www.cnblogs.com/liujiaxin2018/p/14446253.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!