美文网首页
python格式化输出

python格式化输出

作者: slytherinwyne | 来源:发表于2020-01-20 10:00 被阅读0次

格式化输出浮点数(float)

import math

#default

print"PI = %f"%math.pi

#width = 10,precise = 3,align = left

print"PI = %10.3f"%math.pi

#width = 10,precise = 3,align = rigth

print"PI = %-10.3f"%math.pi

#前面填充字符

print"PI = %06d"%int(math.pi)

#输出结果

#PI = 3.141593

#PI = 3.142

#PI = 3.142

#PI = 000003

#浮点数的格式化,精度、度和

格式化输出字符串(string)

#precise = 3

print"%.3s "%("jcodeer")

#precise = 4print"%.*s"%(4,"jcodeer")

#width = 10,precise = 3print"%10.3s"%("jcodeer")

#输出结果:#jco#jcod# jco

相关文章

  • 实战

    python的格式化输出 #python格式化输出 ##%对于未知变量类型,用这样就不太方便了 name='lis...

  • 入门输入输出篇

    python 的输入和输出 输出 print('hello') 格式化输出: 命令行: >>> 'Hello, %...

  • Python2与Python3中print用法总结

    Python2中的print用法 在Python2 中 print 是一种输出语句 1.格式化输出整数 2.格式化...

  • Python 中的常见 格式化符号

    Python 认识格式化输出 中的 格式化符号 在前面的文章里我们早早就接触过Python中的输出的函数prinn...

  • python—输入与输出

    Python的格式化输出 使用字符串格式化的形式来优化Python的输出,使用%作为占位符。%后面跟的是变量的类型...

  • Python使用format与f-string数字格式化

    Python使用format与f-string数字格式化 输出:

  • python笔记

    Python format格式化输出 浅谈 Python 的 with 语句 Python中迭代原理生成器和迭代原...

  • python-print函数的使用

    1.格式化输出 看看《Python基础编程》中对格式化输出的总结: %字符:标记转换说明符的开始 转换标志:-表示...

  • Python自学笔记Day9

    Python自学笔记——Day9 基本输入输出 1. 输出函数及格式化 Python两种输出值的方式: 表达式语句...

  • Python几种格式化输出

    Python格式化输出 print(userInfo)print(userInfo1)print(userInfo...

网友评论

      本文标题:python格式化输出

      本文链接:https://www.haomeiwen.com/subject/otqjzctx.html