+ 1

How to print unicode of a character in python?

I want to print UTF of a character entered by the user. For example:- if the user enters $, the program should print it's unicode, i.e. U+0024

26th Nov 2019, 10:20 AM
Ayush Tripathi
Ayush Tripathi - avatar
4 Respostas
26th Nov 2019, 5:00 PM
OR!ON 🛡️
OR!ON 🛡️ - avatar
+ 1
Ayush Tripathi You could've added the part for reading user input by yourself. Have you learned how to get user input? BTW I have that covered. See updated example.
26th Nov 2019, 1:01 PM
Ipang
0
Thanks for answering the question, but In this, user can't enter the character of which he/she wants the unicode, you're giving the ubicode of just $ cause i used as example.
26th Nov 2019, 12:26 PM
Ayush Tripathi
Ayush Tripathi - avatar
- 1
# Originally from: # https://stackoverflow.com/questions/14678132/JUMP_LINK__&&__python__&&__JUMP_LINK-hexadecimal def fun(s): if len(s) == 0: return 'U+0000' d = format(ord(s[0]), '04x') u = f'U+{d}' return u while True: try: s = input("Enter a character: ") print(s[0]) # for Code Playground r = fun(s) print(f"Unicode for '{s[0]}' is {r}") except (EOFError, ValueError, TypeError): print("(None)") # for Code Playground break
26th Nov 2019, 11:04 AM
Ipang