python中杂乱问题

1 字符串格式化中的格式指定

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

详细信息请转官网

2 查看字符的各种编码方法使用repr

In [3]: a=u""

In [4]: repr(a)
Out[4]: "u'\u554a'"

In [5]: b = a.encode("utf-8")

In [6]: repr(b)
Out[6]: "'\xe5\x95\x8a'"

In [7]: c = a.encode("gbk")

In [8]: repr(c)
Out[8]: "'\xb0\xa1'"
原文地址:https://www.cnblogs.com/zhaopengcheng/p/5817708.html