In Python 2, you have str and unicode types. str is a simple byte string, and unicode is a Unicode string.
For Python 3, this has changed: now str is what was unicode in Python 2 and byte is what str in Python 2.
So, when you do ("x = %s" % '\u041c\u0438\u0440').encode("utf-8") , you can actually omit the u prefix because it is implicit. All that is not explicitly converted to python is unicode.
This will give your last line in Python 3:
("x = %s" % '\u041c\u0438\u0440').encode("utf-8")
Now, as I encode after the final result, what you should always do: take the incoming object, decode it in unicode (how you do it), and then, making a conclusion, encode it in the encoding of your choice. Do not try to process source byte strings. This is just ugly and obscene behavior.
javex source share