字符串对齐
>>> print '|','abc'.ljust(20,'_'),'|','abc'.rjust(20,'_'),'|','abc'.center(20,'_')
| abc_________________ | _________________abc | ________abc_________
>>>
本文介绍了Python中字符串对齐的基本用法,包括左对齐、右对齐及居中对齐。通过实例展示了如何使用特定字符填充空余部分,实现统一的格式输出。
字符串对齐
>>> print '|','abc'.ljust(20,'_'),'|','abc'.rjust(20,'_'),'|','abc'.center(20,'_')
| abc_________________ | _________________abc | ________abc_________
>>>
1061
691
683

被折叠的 条评论
为什么被折叠?