Why do I get the u“xyz” format when I print a list of unicode strings in Python?

前端 未结 3 1314
北恋
北恋 2020-12-18 16:31

Please observe the following behavior:

a = u\"foo\"
b = u\"b\\xe1r\"   # \\xe1 is an \'a\' with an accent
s = [a, b]

print a, b
print s
for x in s: print x,         


        
3条回答
  •  执念已碎
    2020-12-18 16:58

    Objects in Python have two ways to be turned into strings: roughly speaking, str() produces human readable output, and repr() produces computer-readable output. When you print something, it uses str().

    But the str() of a list uses the repr() of its elements.

提交回复
热议问题