To include Unicode characters in your Python source code, you can use Unicode escape characters in the form \u0123
in your string. In Python 2.x, you also need to prefix the string literal with 'u'.
Here's an example running in the Python 2.x interactive console:
>>> print u'\u0420\u043e\u0441\u0441\u0438\u044f'
??????
In Python 2, prefixing a string with 'u' declares them as Unicode-type variables, as described in the Python Unicode documentation.
In Python 3, the 'u' prefix is now optional:
>>> print('\u0420\u043e\u0441\u0441\u0438\u044f')
??????
If running the above commands doesn't display the text correctly for you, perhaps your terminal isn't capable of displaying Unicode characters.
These examples use Unicode escapes (\u...
), which allows you to print Unicode characters while keeping your source code as plain ASCII. This can help when working with the same source code on different systems. You can also use Unicode characters directly in your Python source code (e.g. print u'??????'
in Python 2), if you are confident all your systems handle Unicode files properly.
For information about reading Unicode data from a file, see this answer: