如何在Python中表示Unicode编码的字符串?

huangapple go评论80阅读模式
英文:

How to represent Unicode encoded strings in Python?

问题

I am translating a program from Java to Python.

In the source code of the Java program, the strings use the "\u000x" encoding for a few characters. As I understand, this is the unicode representation of the character and x is a hexadecimal code for that character.

In Java program the string is declared as:

data = "~\\GJ_F^A\u001eXJ]NK\u0018!"

How do I represent this in Python?

The above string has two encoded characters:

\u001e
\u0018

Thanks.
英文:

I am translating a program from Java to Python.

In the source code of the Java program, the strings use the "\u000x" encoding for a few characters. As I understand, this is the unicode representation of the character and x is a hexadecimal code for that character.

In Java program the string is declared as:

data = "~\\GJ_F^A\u001eXJ]NK\u0018!"

How do I represent this in Python?

The above string has two encoded characters:

\u001e
\u0018

Thanks.

答案1

得分: 1

Python 也支持 Unicode 转义代码。 这是有效的 Python 代码:

data = "~\\GJ_F^A\u001eXJ]NK\u0018!"
英文:

Python also has Unicode escape codes. This is valid python:

data = "~\\GJ_F^A\u001eXJ]NK\u0018!"

huangapple
  • 本文由 发表于 2020年4月11日 07:57:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/61150392.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定