如何实现Python中字符串的右对齐实例方法?
- 内容介绍
- 文章标签
- 相关推荐
本文共计534个文字,预计阅读时间需要3分钟。
例如,有一个字典如下所示:pythondic={ name: botoo, url: http://www.jb51.net, page: 88, isNonProfit: true, address: china}想要得到的输出结果如下:plaintextname:botoo url:https://www.jb51.net page:88 isNonProfit:true address:china
例如,有一个字典如下:
>>> dic = { "name": "botoo", "url": "//www.jb51.net", "page": "88", "isNonProfit": "true", "address": "china", }
想要得到的输出结果如下:
name:botoo
url:https:www.jb51.net
page:88
isNonProfit:ture
address:china
首先获取字典的最大值max(map(len, dic.keys()))
然后使用
Str.rjust() 右对齐
或者
Str.ljust() 左对齐
或者
Str.center() 居中的方法有序列的输出。
本文共计534个文字,预计阅读时间需要3分钟。
例如,有一个字典如下所示:pythondic={ name: botoo, url: http://www.jb51.net, page: 88, isNonProfit: true, address: china}想要得到的输出结果如下:plaintextname:botoo url:https://www.jb51.net page:88 isNonProfit:true address:china
例如,有一个字典如下:
>>> dic = { "name": "botoo", "url": "//www.jb51.net", "page": "88", "isNonProfit": "true", "address": "china", }
想要得到的输出结果如下:
name:botoo
url:https:www.jb51.net
page:88
isNonProfit:ture
address:china
首先获取字典的最大值max(map(len, dic.keys()))
然后使用
Str.rjust() 右对齐
或者
Str.ljust() 左对齐
或者
Str.center() 居中的方法有序列的输出。

