新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:python中如何實(shí)現(xiàn)print函數(shù)格式化輸出?
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。

一、print() 方法介紹
用于打印輸出,是python中最常見(jiàn)的一個(gè)函數(shù)。
語(yǔ)法
print(*objects, sep=' ', end='\n', file=sys.stdout)
二、數(shù)據(jù)格式化輸出實(shí)例
1、格式化輸出字符串
print ("His name is %s"%("Aviad"))
2、格式化輸出整數(shù)
strHello = "the length of (%s) is %d" %('Hello World',len('Hello World'))
print strHello
#輸出果:the length of (Hello World) is 11
3、格式化輸出浮點(diǎn)數(shù)
a = 3.1415926 print "%f" %a 輸出為: 3.141593
4、格式化輸出指定占位符寬度
print ("Name:%10s Age:%8d Height:%8.2f"%("Aviad",25,1.83))
以上就是小編總結(jié)四種使用python中print函數(shù)實(shí)現(xiàn)格式化輸出的方式,希望能對(duì)你有所幫助哦~
新聞標(biāo)題:創(chuàng)新互聯(lián)Python教程:python中如何實(shí)現(xiàn)print函數(shù)格式化輸出?
URL網(wǎng)址:http://fisionsoft.com.cn/article/djgddcd.html


咨詢
建站咨詢
