[Python] Conversion to int with Unicode strings

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

  1. Stack

    Stack Membro Participativo

    I recognized that int(unicode_string) sometimes gives obscure results. E.g. int('᪐᭒') == 2.

    >>> bytes('᪐᭒', 'utf-8')
    b'\xe1\xaa\x90\xe1\xad\x92'
    >>> [f'U+{ord(c):04X}' for c in '᪐᭒']
    ['U+1A90', 'U+1B52']


    My expectation would be it fails, because the string does not contain a number.

    Is there some explanation for this behaviour?

    Continue reading...

Compartilhe esta Página