mat
mat

Reputation: 321

Custom value on python unicode \u

I'm quite new to python and i've been trying to get this working with no success.
Is there any way to make something like this work

unicode_code = "00000061"
character = "\u" + unicode_code  

A example would be appreciated.

Upvotes: 0

Views: 144

Answers (1)

JosefZ
JosefZ

Reputation: 30153

Literals are notations for constant values of some built-in types.

Unless an 'r' or 'R' prefix is present, escape sequences in strings are interpreted according to rules similar to those used by Standard C:

  • \uxxxx     Character with 16-bit hex value xxxx (Unicode only)
  • \Uxxxxxxxx Character with 32-bit hex value xxxxxxxx (Unicode only)

Unfortunately, neither "\u" + "0061" nor "\U" + "00000061" satisfy condition of constant values as they both are expressions.

Upvotes: 1

Related Questions