In Python:
>>> "\N{BLACK SPADE SUIT}" '♠' >>> "\u2660" '♠'
Now, let's say I have a character which I don't know the name or number for. Is there a Python function which gives this information like this?
>>> wanted_function('♠') ["BLACK SPADE SUIT", "u2660"]
Use Unicode code points in strings: \x , \u , \U Each code is treated as one character. You can check it with the built-in function len() which returns the number of characters.
Unicode is explicitly defined such as to overlap in that same range with ASCII. Thus, if you look at the character codes in your string, and it contains anything that is higher than 127, the string contains Unicode characters that are not ASCII characters. Note, that ASCII includes only the English alphabet.
To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X.
You may find the unicodedata module handy:
>>> s = "\N{BLACK SPADE SUIT}" >>> s '♠' >>> import unicodedata >>> unicodedata.name(s) 'BLACK SPADE SUIT' >>> ord(s) 9824 >>> hex(ord(s)) '0x2660'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With