When you print a string, you get the output of the __str__
method of the object – in this case the string without quotes. The __str__
method of a list is different, it creates a string containing the opening and closing []
and the string produced by the __repr__
method of each object contained within. What you’re seeing is the difference between __str__
and __repr__
.
You can build your own string instead:
print '[' + ','.join("'" + str(x) + "'" for x in s) + ']'
This version should work on both Unicode and byte strings in Python 2:
print u'[' + u','.join(u"'" + unicode(x) + u"'" for x in s) + u']'