如何使用Python将unicode字符串中的重音字符转换为其unicode字符代码?

发布于 2024-09-14 23:34:24 字数 89 浏览 3 评论 0原文

只是想知道如何将像 u'é' 这样的 unicode 字符串转换为其 unicode 字符代码 u'\xe9'

Just wonder how to convert a unicode string like u'é' to its unicode character code u'\xe9'?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沉默的熊 2024-09-21 23:34:24

您可以使用 Python 的 repr() 函数:

>>> unicode_char = u'é'
>>> repr(unicode_char)
"u'\\xe9'"

You can use Python's repr() function:

>>> unicode_char = u'é'
>>> repr(unicode_char)
"u'\\xe9'"
君勿笑 2024-09-21 23:34:24

ord 将为您提供数值,但您必须将其转换为十六进制:

>>> ord(u'é')
233

ord will give you the numeric value, but you'll have to convert it into hex:

>>> ord(u'é')
233
灼疼热情 2024-09-21 23:34:24

u'é' 和 u'\xe9' 完全相同,只是不同的表示形式:

>>> u'é' == u'\xe9'
True

u'é' and u'\xe9' are exactly the same, they are just different representations:

>>> u'é' == u'\xe9'
True
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文