gpt4 book ai didi

python - 在 python 中编码 : what type is the variable

转载 作者:太空宇宙 更新时间:2023-11-04 07:03:53 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com