How to create a unicode string in python?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Nov 26, 2022, 10:33 AM EST
A character encoding tells the computer how to interpret raw zeroes and ones into real characters. There are many different types of character encodings floating around at present, but the ones we deal most frequently with are ASCII , 8-bit encodings, and Unicode-based encodings. The Unicode Standard provides a unique number for every character, no matter what platform, device, application or language.
In Python 3, all strings are sequences of Unicode characters . You have two options to create Unicode string in Python. Either use decode() , or create a new Unicode string with UTF-8 encoding by unicode(). The unicode() method is unicode(string[, encoding, errors]) , its arguments should be 8-bit strings. The first argument is converted to Unicode using the specified encoding, if encoding argument left, the ASCII encoding is used for the conversion.
Example using Python 3:
regular = "regular string" unicode_string = u"Unicode string" print(type(regular)) print(type(unicode_string))Output:
Brahma Prakash ShuklaRank #633 · 3.8K reputationPosted Nov 26, 2022, 9:17 AM EST
You have two options to create Unicode string in Python. Either use decode() , or create a new Unicode string with UTF-8 encoding by unicode(). The unicode() method is unicode(string[, encoding, errors]) , its arguments should be 8-bit strings.