Official Python tutorial states that Unicode strings in Python can be used like this:
u'Hello World !'
But when I put it to IDLE - Python GUI of Python 3.2, it gives me a syntax error. Also Russian and Chinese text can be succcessfully stored in that Python strings, so I guess they are already Unicode.
Could you please explain what's happening?
by default python 3.2 works with unicode strings so the u
is no longer needed.
If you want to encode and decode strings you should use:
encoded = "unicodestring".encode("UTF8")
decoded = s.decode("UTF8")
The Python documetation states that:
Python 3.0 uses the concepts of text and (binary) data instead of Unicode strings and 8-bit strings. All text is Unicode; however encoded Unicode is represented as binary data. The type used to hold text is str
and
You can no longer use u"..." literals for Unicode text. However, you must use b"..." literals for binary data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With