Mod*_*esq 6 python string unicode
我希望能够在我的python字符串中使用unicode.比如我有一个图标:
icon = '▲'
print icon
Run Code Online (Sandbox Code Playgroud)
应该创建icon ='▲'
但它确实以字符串形式返回它: ▲
如何让这个字符串识别unicode?
提前谢谢你的帮助.
pok*_*oke 10
您可以使用字符串转义序列,如语言参考的"字符串和字节文字"部分所述.对于Python 3,这可以像这样工作:
>>> icon = '\u25b2'
>>> print(icon)
?
Run Code Online (Sandbox Code Playgroud)
在Python 2中,这仅适用于unicode字符串.Unicode字符串u在引号前面有一个前缀:
>>> icon = u'\u25b2'
>>> print icon
?
Run Code Online (Sandbox Code Playgroud)
这在Python 3中不是必需的,因为Python 3中的所有字符串都是unicode字符串.
| 归档时间: |
|
| 查看次数: |
8864 次 |
| 最近记录: |