2

I have a slight problem that may be unsolvable in python. Can you use an integer variable to type unicode in python? For example, let's say you have a variable: `variable = 0041`. Can you do something like (without having to manually type it) get `\u0041` (`a`)?
I have not really tried anything because nothing comes to mind when I try to solve this problem. If there is a possible solution, what is it?

Sorry if the answer is painfully obvious or I did not provide enough information, I'm new to this.

Nikhil R.
  • 25
  • 4
  • 4
    Does this answer your question? [How to get the ASCII value of a character](https://stackoverflow.com/questions/227459/how-to-get-the-ascii-value-of-a-character) – Macattack Apr 24 '21 at 20:58
  • 1
    Note that `variable = 0041` won't work, leading zeros aren't allowed. Even if you removed them the number is interpreted as decimal, not hex. You could use `variable = 0x41`. – Mark Ransom Apr 24 '21 at 21:01

1 Answers1

2

This is what the chr function is for.

>>> chr(int('0041', 16))
'A'
Mark Ransom
  • 299,747
  • 42
  • 398
  • 622