python 字符串对齐

场景:

字符串对齐

python提供非常容易的方法,使得字符串对齐

  >>> print("abc".center (30,'-')) 
  -------------abc--------------                        
  >>>
print("abc".ljust (30)+'|'
) 
  abc                           | 
  >>>
print("abc"
.rjust (30)) 
                             abc 
  >>>  

分别是center,ljust,rjust

三个方法默认填充是空格,也可以使用其他字符填充

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2021-09-23
猜你喜欢
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
相关资源
相似解决方案