1,ljust()→居左
2,rjust()→居右
3,center()→居中
输入:
a = “这就是命!”
print(a.ljust(20))
print(a.rjust(20))
print(a.center(20))
print(a.ljust(20,’*’))
print(a.rjust(20,’*’))
print(a.center(20,’*’))
输出:
4,通过format()函数格式化实现居左,居右,居中:
输入:
a = “蜡笔小新”
print(format(a,’>20’))
print(format(a,’<20’))
print(format(a,’^20’))
print(format(a,’$>20’))
print(format(a,’$<20’))
print(format(a,’$^20’))
输出: