Python 3 将“Д”转换为字符串的函数
Python 3 function to convert "Д" to string
任务是将Де
转换为Де
。
Python 3 是否有内置函数,或者我需要解析这个字符串,然后使用内置的 chr
方法将每个数字转换为字符串?
您可以使用html.unescape
函数:
<b>import html</b>
text = 'Де'
result = <b>html.unescape(</b>text<b>)</b>
在python 3.4及以上版本中,您可以使用html.unescape
:
>>> import html
>>> print(html.unescape('Де'));
Де
任务是将Де
转换为Де
。
Python 3 是否有内置函数,或者我需要解析这个字符串,然后使用内置的 chr
方法将每个数字转换为字符串?
您可以使用html.unescape
函数:
<b>import html</b>
text = 'Де'
result = <b>html.unescape(</b>text<b>)</b>
在python 3.4及以上版本中,您可以使用html.unescape
:
>>> import html
>>> print(html.unescape('Де'));
Де