字符串

来源:互联网 发布:mac系统恢复u盘制作 编辑:程序博客网 时间:2024/06/05 05:41

#指定输出宽度

print '%10f' % pi


#制定输出宽度和精度

print '%10.2f' % pi


#指定输出精度

print '%.2f'' %pi


#用0补充

print '%010.2f' %pi

#用空格补充

 print '% 5d' % 10


#用*取得宽度或精度

print '%.*s' % (5, 'teststring')


#减号-:左对齐

print '%-10.2f' %pi


#用+标出正负号

 print ('%+5d' % 10) + '\n' + ('%+5d' % -10)