python中的数字格式

python中的数字格式,python,formatting,number-formatting,Python,Formatting,Number Formatting,如何生成此python代码: # -*- coding: cp1252 -*- a=4 b=2 c=1.0 d=1.456 print '%fx³ + %fx² + %fx + %f = 0' %(a,b,c,d) 打印如下: 4x³ + 2x² + 1x + 1.456 = 0 而不是像这样(它当前的打印方式): 使用此> 4.000000x³ + 2.000000x² + 1.0000000x + 1.456000 = 0 print '%gx³ + %gx² + %gx + %g =

如何生成此python代码:

# -*- coding: cp1252 -*-
a=4
b=2
c=1.0
d=1.456
print '%fx³ + %fx² + %fx + %f = 0' %(a,b,c,d)
打印如下:

4x³ + 2x² + 1x + 1.456 = 0
而不是像这样(它当前的打印方式):

使用此>

4.000000x³ + 2.000000x² + 1.0000000x + 1.456000 = 0
print '%gx³ + %gx² + %gx + %g = 0' %(a,b,c,d)