In python, how do you get the escape sequence for any Unicode character?

63 Views Asked by At

In python, what is the escape sequence for the left-double quote Unicode character (U+201C)?

left_double_quote = "“"

print(ord(left_double_quote)) # prints `8220`

Note that 201C is hexadecimal notation for the decimal number 8220

I tried somethings, but it did not work:

print("\x8220")
print("\x201C")
print("\0x201C")
1

There are 1 best solutions below

0
Matthias Fripp On

You can use the \u escape to indicate you are specifying unicode bytes rather than hex (ASCII?) bytes.

So for your example, you can use this:

print("\u201c")

# output: “