
正文
python中杂乱问题
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
1 字符串格式化中的格式指定
format_spec ::= [[fill]align][sign][#][][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 []: a=u"啊"In []: repr(a)
Out[]: "u'\\u554a'"In []: b = a.encode("utf-8")In []: repr(b)
Out[]: "'\\xe5\\x95\\x8a'"In []: c = a.encode("gbk")In []: repr(c)
Out[]: "'\\xb0\\xa1'"








