Python格式化输出
2023-02-18 16:29:48 时间
1.打印字符串
Python X
>>>print ("His name is %s"%("Aviad"))
His name is Aviad
2.打印整数
Python X
>>>print ("His is %d years old"%(25))
His is 25 years old
3.打印浮点数
Python X
>>>print ("His height is %f m"%(1.83))
His height is 1.830000 m
4.打印浮点数(指定保留小数位数)
Python X
>>>print ("His height is %.2f m"%(1.83))
His height is 1.83 m
5.指定占位符宽度
Python X
>>>print ("Name:%10s Age:%8d Height:%8.2f"%("Aviad",25,1.83))
Name: Aviad Age: 25 Height: 1.83
6.指定占位符宽度(左对齐)
Python X
>>>print ("Name:%-10s Age:%-8d Height:%-8.2f"%("Aviad",25,1.83))
Name:Aviad Age:25 Height:1.83
7.指定占位符(只能用0作占位符?)
Python X
>>>print ("Name:%-10s Age:%08d Height:%08.2f"%("Aviad",25,1.83))
Name:Aviad Age:00000025 Height:00001.83
8.科学计数法
Python X
>>>format(0.0015,'.2e')
'1.50e-03'
本文采用 「CC BY-NC-SA 4.0」创作共享协议,转载请标注以下信息: 原文出处:Yiiven https://www.yiiven.cn/python-output-formart.html
相关文章
- PyQt5+python+pycharm开发环境配置
- MySQL 存储引擎、锁、调优、失误与事务回滚、与python交互、orm
- python 多态、多继承、函数重写、迭代器
- python 读取或写入文件
- python 迭代器与生成器
- python 错误与异常
- python 装饰器
- python 高阶函数
- python:列表
- python 模块
- python 函数
- python 字符串
- KG4Py:Python代码知识图谱和语义搜索的工具包
- [oeasy]python0032_杀死进程_进程后台运行不输出_nohup_ps_显示进程
- Python 实用技能 RAPIDS | 利用 GPU 加速数据科学工作流程
- Linux Python开发平台Ubuntu
- Python定制篇-APT软件管理和远程登录
- Python 文件
- Python 模块与包
- Python 元组和集合