[Python] How to get UTF-16 (decimal) in Python?

Discussão em 'Python' iniciado por Stack, Abril 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have Unicode Code Point of an emoticon represented as U+1F498:

    emoticon = u'\U0001f498'


    I would like to get utf-16 decimal groups of this character, which according to this website are 55357 and 56472.

    I tried to do print emoticon.encode("utf16") but did not help me at all because it gives some other characters.

    Also, trying to decode from UTF-8 before encode it to UTF-16 as follow print str(int("0001F498", 16)).decode("utf-8").encode("utf16") does not help either.

    How do I correctly get the utf-16 decimal groups of a unicode character?

    Continue reading...

Compartilhe esta Página