+ 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
4 Answers
+ 3
Try this đ
https://code.sololearn.com/cAzX4Sr8d8N5/?ref=app
+ 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.
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.
- 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