How to ignore the escaping \ python list?
问题 I want to ignore the escape character in the following code. >>> a=['\%'] >>> print a ['\\%'] I want to output like ['\%'] . Is there any way to do that? 回答1: Using string_escape , unicode_escape encoding (See Python Specific Encodings): >>> a = ['\%'] >>> print str(a).decode('string_escape') ['\%'] >>> print str(a).decode('unicode_escape') ['\%'] 回答2: Couple of manual ways: >>> a=['\%'] >>> print "['{}']".format(a[0]) ['\%'] >>> print "['%s']" % a[0] ['\%'] Or more generally: >>> a=['\%', '\