zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Pythonljustrjustcenter输出

2023-06-13 09:14:02 时间
看下面的例子就会明白了:
复制代码代码如下:

print"|","*".ljust(10),"|"
print"|","*".ljust(10,"-"),"|"
print"|","*".rjust(10,"-"),"|"
print"|","*".center(10,"-"),"|"


forainrange(1,6):
print"a=".ljust(5),repr(a).ljust(10),"b=".ljust(5),repr(a*2)

输出结果:
|*|
|*---------|
|---------*|
|----*-----|
a=1b=2
a=2b=4
a=3b=6
a=4b=8
a=5b=10