Python文件
# -*- coding: UTF-8 -*-
a = 'Köppler'
print a
print a.__class__.__name__
mydict = {}
mydict['name'] = a
print mydict
print mydict['name']
输出:
Köppler
str
{'name': 'K\xc3\xb6ppler'}
Köppler
名称似乎保持不变,但只有在打印字典时我才会得到这个奇怪的转义字符串。那我在看什么?那是 UTF-8 表示吗?
最佳答案
该行为的原因是 Python 2 中的 __repr__
函数 escapes non-ASCII unicode characters .如链接所示,这已在 Python 3 中修复。
关于python - 在 python 中编码 : what type is the variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5376328/