Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape Unicode in Python 3

So I know that the character "Latin Small Letter Sharp S" ß is at Unicode Point U+00DF and I know how to escape this in Python 3 as a string: \u00DF.

However, I know that there are other unicode prefixes for the larger codepoints (such as U+260E: Black Telephone)

I have seen the uppercase U being used such as \U00DF and i have also seen \x being used.

My question is when do i use those. For instance many emoji are just given as U+260x. And my thought is to use a capital U and fill in 12 0s before those digits but when do I use an \x and when do I know to use leading zeros (and how many)

All of this is me guessing because I can't find any documentation.

like image 935
Startec Avatar asked Oct 27 '25 14:10

Startec


1 Answers

The \x takes two hex digits. The lower-case \u takes four hex digits. The upper-case \U takes eight hex digits.

https://docs.python.org/3/howto/unicode.html#unicode-literals-in-python-source-code

like image 153
Andrew Janke Avatar answered Oct 30 '25 05:10

Andrew Janke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!