How can I create a Python tuple of Unicode strings?


You can create a tuple of unicode strings in python using the u'' syntax when defining this tuple. 

example

a = [(u'亀',), (u'犬',)]
print(a)

Output

This will give the output

[('亀',), ('犬',)]

Note that you have to provide the u if you want to say that this is a unicode string. Else it will be treated as a normal binary string. And you'll get an unexpected output. 

example

a = [('亀',), ('犬',)]
print(a)

Output

This will give the output

[('\xe4\xba\x80',), ('\xe7\x8a\xac',)]

Updated on: 05-Mar-2020

133 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements