python中請(qǐng)問(wèn)怎么格式化輸出列表?
python用print進(jìn)行格式化輸出,有以下幾種模式,代碼如下:
1、打印字符串print ("His name is %s"%("Aviad"))效果:
2、打印整數(shù)print ("He is %d years old"%(25))效果:
3、打印浮點(diǎn)數(shù)print ("His height is %f m"%(1.83))效果:
4、打印浮點(diǎn)數(shù)(指定保留小數(shù)點(diǎn)位數(shù))print ("His height is %.2f m"%(1.83))效果:
5、指定占位符寬度print ("Name:%10s Age:%8d Height:%8.2f"%("Aviad",25,1.83))效果:
6、指定占位符寬度(左對(duì)齊)print ("Name:%-10s Age:%-8d Height:%-8.2f"%("Aviad",25,1.83))效果:
7、指定占位符(只能用0當(dāng)占位符?)print ("Name:%-10s Age:%08d Height:%08.2f"%("Aviad",25,1.83))效果:8、科學(xué)計(jì)數(shù)法format(0.0015,'.2e')效果: