0
点赞
收藏
分享

微信扫一扫

Python3的字符串格式化

芷兮离离 2022-04-14 阅读 66

Python3里的字符串格式化功能很强大,新手看到下面的形式描述可能会比较害怕:

format_spec     ::=  [[fill]align][sign][#][0][width][grouping_option][.precision][type]
fill            ::=  <any character>
align           ::=  "<" | ">" | "=" | "^"
sign            ::=  "+" | "-" | " "
width           ::=  digit+
grouping_option ::=  "_" | ","
precision       ::=  digit+
type            ::=  "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"

我先挑出比较常用的,画了一张图,底下配了几个常用的例子:在这里插入图片描述

当然,更全面的、更复杂的也画了:
在这里插入图片描述

举报

相关推荐

0 条评论