Python ljust rjust center输出
2008-09-06 13:25
666 查看
看下面的例子就会明白了:
复制代码 代码如下:
print '|','*'.ljust(10),'|'
print '|','*'.ljust(10,'-'),'|'
print '|','*'.rjust(10,'-'),'|'
print '|','*'.center(10,'-'),'|'
for a in range(1, 6):
print 'a = '.ljust(5), repr(a).ljust(10), 'b = '.ljust(5), repr(a * 2)
输出结果:
| * |
| *--------- |
| ---------* |
| ----*----- |
a = 1 b = 2
a = 2 b = 4
a = 3 b = 6
a = 4 b = 8
a = 5 b = 10
复制代码 代码如下:
print '|','*'.ljust(10),'|'
print '|','*'.ljust(10,'-'),'|'
print '|','*'.rjust(10,'-'),'|'
print '|','*'.center(10,'-'),'|'
for a in range(1, 6):
print 'a = '.ljust(5), repr(a).ljust(10), 'b = '.ljust(5), repr(a * 2)
输出结果:
| * |
| *--------- |
| ---------* |
| ----*----- |
a = 1 b = 2
a = 2 b = 4
a = 3 b = 6
a = 4 b = 8
a = 5 b = 10
相关文章推荐
- Python ljust rjust center输出
- python: center、ljust、rjust 函数
- python中字符串的ljust、rjust、center方法讲解
- python中字符串的ljust、rjust、center方法讲解
- python中字符串的ljust、rjust、center方法讲解
- Python天天美味(5) - ljust rjust center
- python中字符串的ljust、rjust、center方法讲解
- python str方法之ljust、rjust、center
- python中字符串的ljust、rjust、center
- python3----ljust rjust center
- Python: ljust()|rjust()|center()字符串对齐
- python 字符串创建,遍历,切片,格式化ljust rjust center,find,replace,split,repr,str
- Python天天美味(5) - ljust rjust center(转)
- 从零开始学Python3之九——输入与输出
- python 浅析格式化输出和深浅copy
- python输出字典中的中文
- ①Python学习之输出菱形
- python练习:获取一个目录后,遍历输出
- python 指南 输入和输出
- python 常见面试问题(1)-python 输出中文问题/求list的交集或差集/一个简单的socket编程/python 异常处理