Python格式化输出%s和%d
作者:我爱素妍 时间:2021-05-02 14:13:08
本文介绍了Python格式化输出%s和%d的实例案例。分享给大家供大家参考,具体如下:
python print格式化输出
1. 打印字符串
print ("His name is %s"%("Aviad"))
效果:
2.打印整数
print ("He is %d years old"%(25))
效果:
3.打印浮点数
print ("His height is %f m"%(1.83))
效果:
4.打印浮点数(指定保留小数点位数)
print("His height is %.2f m"%(1.83))
效果:
5.指定占位符宽度
print ("Name:%10s Age:%8d Height:%8.2f"%("Aviad",25,1.83))
效果:
6.指定占位符宽度(左对齐)
print ("Name:%-10s Age:%-8d Height:%-8.2f"%("Aviad",25,1.83))
效果:
7.指定占位符(只能用0当占位符?)
print ("Name:%-10s Age:%08d Height:%08.2f"%("Aviad",25,1.83))
效果:
8.科学计数法
format(0.0015,'.2e')
效果:
来源:https://blog.csdn.net/u013216667/article/details/51316971
标签:python,格式化输出,%s,%d
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
django model object序列化实例
2022-07-03 14:55:24
numpy实现神经网络反向传播算法的步骤
2021-02-11 10:54:34
![](https://img.aspxhome.com/file/2023/5/77915_0s.jpg)
Python struct.unpack
2023-10-14 21:29:56
Javascript基础学习之十个重要问题
2023-07-14 09:17:52
Python与AI分析时间序列数据
2022-02-25 09:36:07
![](https://img.aspxhome.com/file/2023/2/104872_0s.jpg)
深入了解Hybrid App技术的相关知识
2023-08-10 09:36:02
Bootstrap3制作自己的导航栏
2023-08-23 02:13:08
![](https://img.aspxhome.com/file/2023/2/56082_0s.png)
PHP hex2bin()函数用法讲解
2023-06-06 18:51:35
![](https://img.aspxhome.com/file/2023/5/55385_0s.png)
Yii配置与使用memcached缓存的方法
2023-11-05 06:34:45
python使用pymongo与MongoDB基本交互操作示例
2023-11-27 03:33:19
![](https://img.aspxhome.com/file/2023/5/88025_0s.png)
Python学习之书写格式及变量命名
2023-08-23 14:53:08
另类读写:ACCESS中Field对象的标题属性
2008-11-28 16:47:00
使用Microsoft SQL Server 2000全文搜索功能构建Web搜索应用程序
2008-09-29 12:32:00
两个不太常用的 CSS Hack
2008-06-27 12:49:00
不错的广告定位效果代码
2009-06-05 18:51:00
用代码帮你了解Python基础(3)
2021-03-20 07:22:46
Docker部署Python爬虫项目的方法步骤
2023-03-27 14:45:21
在OracleE数据库的字段上建立索引的方法
2009-02-26 10:34:00
Python实现抓取网页并且解析的实例
2022-01-12 13:24:53
python绘制简单彩虹图
2022-09-06 04:55:14
![](https://img.aspxhome.com/file/2023/2/115492_0s.jpg)