美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

创新互联Python教程:python中如何实现print函数格式化输出?

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。    

一、print() 方法介绍

用于打印输出,是python中最常见的一个函数。

语法

print(*objects, sep=' ', end='\n', file=sys.stdout)

二、数据格式化输出实例

1、格式化输出字符串

print ("His name is %s"%("Aviad"))

2、格式化输出整数

strHello = "the length of (%s) is %d" %('Hello World',len('Hello World'))
print strHello
#输出果:the length of (Hello World) is 11

3、格式化输出浮点数

a = 3.1415926
print "%f" %a
输出为:
3.141593

4、格式化输出指定占位符宽度

print ("Name:%10s Age:%8d Height:%8.2f"%("Aviad",25,1.83))

以上就是小编总结四种使用python中print函数实现格式化输出的方式,希望能对你有所帮助哦~


文章标题:创新互联Python教程:python中如何实现print函数格式化输出?
转载源于:http://www.zsjierui.cn/article/djgddcd.html

其他资讯