美文网首页
Python强大的格式化format

Python强大的格式化format

作者: shuff1e | 来源:发表于2018-03-27 20:01 被阅读12次
  • https://www.cnblogs.com/wongbingming/p/6848701.html
  • Python Cookbook
  • 格式限定符
    它有着丰富的的“格式限定符”(语法是{}中带:号),比如:
    填充与对齐
    填充常跟对齐一起使用
    ^、<、>分别是居中、左对齐、右对齐,后面带宽度
  • :号后面带填充的字符,只能是一个字符,不指定的话默认是用空格填充
  • 精度与类型f
    精度常跟类型f一起使用
  • 其他类型
    主要就是进制了,b、d、o、x分别是二进制、十进制、八进制、十六进制。
  • 用,号还能用来做金额的千位分隔符。
  • 格式转化
    !s、!a、!r
    一个对象本身不是str,ascii,repr格式,可以使用!s、!a、!r,将其转成str,ascii,repr
>>> '{0:<8}{1:>3}'.format('hello',"world")
'hello   world'
>>> 
KeyboardInterrupt
>>> print '{0:<8}{1:>3}'.format('hello',"world")
hello   world

相关文章

  • format() 格式化函数

    Python format 格式化函数 | 菜鸟教程

  • Python强大的格式化format

    https://www.cnblogs.com/wongbingming/p/6848701.html Pytho...

  • 字符串与编码

    Python的字符串 格式化 format() 代码案例

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

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

  • python笔记

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

  • Python format

    Python 2.6+中,format()是一个非常强大的函数,可以帮助我们填充、格式化字符串。 语法 字符串中,...

  • format()函数

    python中format函数用于字符串的格式化 通过关键字 通过位置 format()方法格式控制 format...

  • Pytorch

    1. Python format 格式化函数: here using . formatto automatic...

  • 2018-07-06

    python格式化输出%与format方法对比 本来已经学完字符串的format格式,今天看到还有...

  • 013.Python格式化

    Python格式化 1. 概述 Python2.6 开始,新增了一种格式化字符串的函数 str.format(),...

网友评论

      本文标题:Python强大的格式化format

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