python格式化输出
2016-05-31 20:22
435 查看
1.打印字符串
>>> print "I'm %s" % ("jihite") I'm jihite
2.打印整数
>>> print "I'm %d years old" % (17) I'm 17 years old
3.打印浮点数
>>> print "π=%f" % (3.1415926) π=3.141593
4.打印浮点数(指定保留小数点位数)
>>> print "π=%.3f" % (3.1415926) π=3.142
5.指定占位符宽度
>>> print "NAME:%8s AGE:%8d WEIGHT:%8.2f" % ("jihite", 17, 62.2) NAME: jihite AGE: 17 WEIGHT: 62.20
6.指定占位符宽度(左对齐)
>>> print "NAME:%-8s AGE:%-8d WEIGHT:%-8.2f" % ("jihite", 17, 62.2) NAME:jihite AGE:17 WEIGHT:62.20
7.指定占位符(只能用0当占位符)
>>> print "NAME:%-8s AGE:%08d WEIGHT:%08.2f" % ("jihite", 17, 62.2) NAME:jihite AGE:00000017 WEIGHT:00062.20
8.科学计数法
>>> format(0.0000023, '.2e') '2.30e-06' >>> format(0.23, '.2e') '2.30e-01'
相关文章推荐
- Python装饰器详解
- leetcode 64. Minimum Path Sum-最小路径和|动态规划
- HighCharts绘图 + Python解析文本
- 简单爬虫
- ubuntu python django环境部署
- Python学习笔记 2 字符串的操作大全
- python基础之socket与socketserver
- python 与时间有关的操作
- Python检查服务器端口是否连接成功
- Python+socket获取本机IP地址
- Python使用wxPython、py2exe编写桌面程序-部署环境
- Python格式化日期
- Python 命名空间
- Python 2x -> 3.x
- 图像处理DOG 算法,python结合cv2实现
- Python【8】-分析json文件
- Python数据分析入门
- Python 编码风格指南
- ERROR (ProgrammingError) (2014, "Commands out of sync; you can't run this command now")
- Google开源的Python格式化工具YAPF的安装和使用教程