this is the code:
varUnicode = input('tEnter your Unicodent>') print('u{}'.format(varUnicode))
i want to get unicode input from user and print the character. in the above code python gives me an error.
Advertisement
Answer
u
is an escape sequence recognized in string literals:
Escape sequences only recognized in string literals are:
JavaScriptx81Escape Meaning Notes
2Sequence
3
4N{name} Character named name
5in the Unicode database (4)
6uxxxx Character with 16-bit hex value xxxx (5)
7Uxxxxxxxx Character with 32-bit hex value xxxxxxxx (6)
8
Notes:
- Changed in version 3.3: Support for name aliases 1 has been added.
- Exactly four hex digits are required.
- Any Unicode character can be encoded this way. Exactly eight hex digits are required.
Use
JavaScript
1
3
1
varUnicode = input('tEnter your Unicodent>')
2
print('\u{}'.format(varUnicode.zfill(4)).encode('raw_unicode_escape').decode('unicode_escape'))
3
or (maybe better)
JavaScript
1
3
1
varUnicode = input('tEnter your Unicodent>')
2
print('\U{}'.format(varUnicode.zfill(8)).encode('raw_unicode_escape').decode('unicode_escape'))
3