源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Python中字符串对齐方法介绍

  • 时间:2020-09-26 21:29 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Python中字符串对齐方法介绍
[b]目的[/b]   实现字符串的左对齐,右对齐,居中对齐。 [b]方法 [/b]   字符串内置了以下方法:其中width是指包含字符串S在内的宽度,fillchar默认是空格,也可以指定填充字符
[u]复制代码[/u] 代码如下:
string.ljust(s, width[, fillchar]) string.rjust(s, width[, fillchar]) string.center(s, width[, fillchar])
[u]复制代码[/u] 代码如下:
In [6]: a='Hello!' In [7]: print a.ljust(10,'+') Hello!++++ In [8]: print a.rjust(10,'+') ++++Hello! In [9]: print a.center(10,'+') ++Hello!++
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部